标签:
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13510 Accepted Submission(s):
6000
#include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> using namespace std; bool cmp(int a,int b) { return a<b; } int main() { int n,m,j,i,s,t,sum; int a[1100]; scanf("%d",&n); while(n--) { scanf("%d",&m); sum=0;s=0; for(i=0;i<m;i++) scanf("%d",&a[i]); sort(a,a+m,cmp); if(m%2!=0) { s=(m-1)/2; for(i=0;i<m;i++) { sum+=abs(a[i]-a[s]); } } else { s=m/2-1; for(i=0;i<m;i++) { sum+=abs(a[i]-a[s]); } } printf("%d\n",sum); sum=0; } return 0; }
标签:
原文地址:http://www.cnblogs.com/tonghao/p/4546639.html