PersonalCorpus 版 (精华区)
1247843 Big Guava ... 10041 Accepted
0:00.135 404 2002/11/19 05:32:10.922
int cmp(const void *a, const void *b)
{
int x=*(int *)a;
int y=*(int *)b;
if (x>y) return 1; else if (x==y) return 0;else return -1;
}
void main()
{
#ifndef ONLINE_JUDGE
freopen("k:\\uva\\i10041","r",stdin);
freopen("k:\\uva\\o10041","w",stdout);
#endif
int i,j,k,t,n,c[500];
scanf("%d",&t);
while (t--) {
scanf("%d",&n);
for (i=0;i<n;i++) scanf("%d",&c[i]);
qsort(c,n,4,cmp);
k=n/2; j=0;
for (i=0;i<n;i++) j+=abs(c[i]-c[k]);
printf("%d\n",j);
}
}
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.243毫秒