| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
两种方法,一种过了,还有一种没有过,奇怪了~~用了两种方法,一种过了,还有一种没有过,反复测试了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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator