hdu2083 简易版之最短距离

点A和点B之间随意一点到A的距离+到B的距离=|AB|,而AB外的一点到A的距离+到B的距离>|AB|;

#include<math.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int cmp(const void *a,const void *b)
{
    return *(int *)a-*(int *)b;
}
int main(void)
{
    int t,n;
    int x[500];
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(int i=0; i<n; i++)
            scanf("%d",&x[i]);
        qsort(x,n,sizeof(x[0]),cmp);
        int sum=0;
        for(int i=0; i<n/2; i++)
            sum+=x[n-i-1]-x[i];
        printf("%d\n",sum);
    }
    return 0;
}


posted on 2015-05-15 14:36  gcczhongduan  阅读(201)  评论(0编辑  收藏  举报