标签:style blog http io ar color os sp for
2 3 1 1 2 1 1 2 5 2 9 5 20 11 9 1 1 1 20
2 44
参考别人思路才AC:
先找横纵坐标的中位数(即邮局位置),然后由于街道只有水平和竖直两个方向,
因此最短距离为各个位置的横纵坐标与邮局的绝对值,近一步化简易得以下代码 。
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
	int a[22],b[22];
	int test,i,n,sum;
	scanf("%d",&test);
	while(test--)
	{
		scanf("%d",&n);
		for(i=0;i<n;i++)
		   scanf("%d%d",&a[i],&b[i]);
		sort(a,a+n);
		sort(b,b+n);
		for(i=0,sum=0;i<n/2;i++)
		{
		   sum+=a[n-1-i]-a[i]+b[n-1-i]-b[i];
	    }
		printf("%d\n",sum);
	}
	return 0;
}
标签:style blog http io ar color os sp for
原文地址:http://blog.csdn.net/hdd871532887/article/details/41764897