http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1944
代码:
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<map> #include<vector> #include<stack> #include<set> #include<map> #include<queue> #include<algorithm> #include<cmath> #define LL long long //#pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const int INF=0x7fffffff; const int N=1005; int x[N],y[N]; int main() { //freopen("data.in","r",stdin); int n; int ca=1; while(true) { scanf("%d",&n); if(!n) break; for(int i=0;i<n;++i) scanf("%d %d",&x[i],&y[i]); sort(x,x+n); sort(y,y+n); int sum=0; int X=x[(n-1)/2]; int Y=y[(n-1)/2]; for(int i=0;i<n;++i) sum+=(abs(x[i]-X)+abs(y[i]-Y)); printf("Case %d: (%d,%d) %d\n",ca++,X,Y,sum); } return 0; }