hdu2083-简易版之最短距离

http://acm.hdu.edu.cn/showproblem.php?pid=2083

#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include "math.h"
#include "algorithm"
#include "iostream"

using namespace std;
#define maxn 505
int num[ maxn ] ;

int main()
{
	int n ,Case , i , j;
	scanf( "%d" , &Case );
	while( Case-- )
	{
		scanf( "%d" , &n ) ;
		for( i = 0 ; i < n ; i++ )
			scanf( "%d" , &num[ i ] );
		sort( num , num + n ) ;
		int sum = 0 ;
		for( i = 0 ; i < n ; i++ )
			sum += abs( num[ n / 2 ] - num[ i ] ) ;
		printf( "%d\n" , sum ) ;
	} 	
	return 0;
}


你可能感兴趣的:(杭电,水题)