标签:
1 #include<stdio.h>//街区最短问题(7) 2 #include<string.h> 3 #include<stdlib.h> 4 int cmp(const void *a,const void *b){ 5 return *(int*)a-*(int*)b; 6 } 7 int main() 8 { 9 int x,y,i,a[110],b[110],sum; 10 scanf("%d",&x); 11 while(x--){ 12 scanf("%d",&y); 13 for(i=0;i<y;i++){ 14 scanf("%d%d",&a[i],&b[i]); 15 } 16 qsort(a,y,sizeof(a[0]),cmp); 17 qsort(b,y,sizeof(b[0]),cmp); 18 sum=0; 19 for(i=0;i<y/2;i++){ 20 sum=sum+a[y-i-1]-a[i]+b[y-i-1]-b[i]; 21 } 22 printf("%d\n",sum); 23 } 24 return 0; 25 }
标签:
原文地址:http://www.cnblogs.com/minimalism/p/4537632.html