Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

两种方法,一种过了,还有一种没有过,奇怪了~~

Posted by lihuiyykl at 2009-07-22 22:14:11 on Problem 2231
用了两种方法,一种过了,还有一种没有过,反复测试了N多种数据,并没有发现第二种方法的问题,有时间大家帮忙找找茬:贴码下
#include<iostream>
#include<cmath>

using namespace std;
#define MAX 100000000
int array[MAX];

int comp(const void *a,const void *b)
{
    return *(int *)a-*(int *)b;
}

int main()
{
    long long n;
    while(cin>>n)
    {
          for(int i=0;i<n;i++) cin>>array[i];
          qsort(array,n,sizeof(int),comp);
          long long total=0;
          int t=n-1;
          int i,j;
          i=0;j=n-1;
          while(t>0)
          {
              total=total+t*(array[j]-array[i]);
              t=t-2;
              i++;
              j--;
          }
          total=2*total;
          cout<<total<<endl; 
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator