标签:des blog io ar os sp for 数据 on
2 2 2 4 3 2 4 6
2 4
解:
#include <stdio.h>
#include <math.h>
int main()
{
int n,m,a[502],i,j,t,loc,sum;
while(scanf("%d",&n)!=EOF)
{
while(n--)
{
scanf("%d",&m);
for(i=0;i<m;i++)
{
scanf("%d",&t);
a[i]=t;
}
loc=0; t=5000000;
for(i=0;i<m;i++)
{
sum=0;
for(j=0;j<m;j++)
{
sum+=abs(a[j]-a[i]);
if(sum>=t) break;
}
if(sum<t) {t=sum; loc=i;}
}
printf("%d",t);
putchar(‘\n‘);
}
}
return 0;
}
标签:des blog io ar os sp for 数据 on
原文地址:http://www.cnblogs.com/tianyong/p/4124072.html