中位数,A,B,C为3点,若C在A,B之间,则C到A,B的和为(B-A),若C<A或者A>B,则C到A,B的距离和肯定大于(B-A)
#include "stdio.h"
#define ABS(t) ((t)>0?(t):-(t))
void main(){
int m, n;
int i, j, t;
int dis[501];
freopen("in.txt", "r", stdin);
scanf("%d", &m);
while(m--){
scanf("%d", &n);
scanf("%d", dis);
for(i=1; i<n; i++){
scanf("%d", dis+i);
t = dis[i];
for(j=i-1; j>=0; j--) //排个序
if(dis[j]>t)
dis[j+1] = dis[j];
else
break;
dis[j+1] = t;
}
t = 0;
for(i=0; i<n/2; i++) t += ABS(dis[i]-dis[n-1-i]);
printf("%d\n", t);
}
}