HDU 1173 采矿
2012-10-13 16:42
295 查看
设答案为x,y
则距离的运算公式为|x-x1|+|x-x2|+...+|x-xn|+|y-y1|+|y-y2|+...+|y-yn|
因此当x,y均为中位数时上式最小
用cin耗时2687ms
用scanf耗时453ms
则距离的运算公式为|x-x1|+|x-x2|+...+|x-xn|+|y-y1|+|y-y2|+...+|y-yn|
因此当x,y均为中位数时上式最小
用cin耗时2687ms
用scanf耗时453ms
#include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<vector> #include<queue> using namespace std; const int maxN=1000010; struct Point{ double x,y; }p[maxN]; bool cmpx(Point a,Point b){ return a.x<b.x; } bool cmpy(Point a,Point b){ return a.y<b.y; } int main(){ #ifndef ONLINE_JUDGE freopen("a.in","r",stdin); //freopen("a.out","w",stdout); #endif int n; while(cin>>n,n){ for(int i=0;i<n;++i) scanf("%lf%lf",&p[i].x,&p[i].y); sort(p,p+n,cmpx); printf("%.2f\n",p[n/2].x); sort(p,p+n,cmpy); printf("%.2f\n",p[n/2].y); } return 0; }