http://acm.hdu.edu.cn/showproblem.php?pid=1173
题意:给出二维平面上的n个点的坐标,求一个点使得这个点到这n个点的距离和最小,若有多个点满足条件,输出任意一个。
不告诉我是中位数,我真的想不到。。。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n;
int main()
{
while(scanf("%d",&n)&&n!=0)
{
double x[1000010],y[1000010];
for(int i=1;i<=n;i++)
scanf("%lf%lf",&x[i],&y[i]);
sort(x+1,x+1+n);
sort(y+1,y+1+n);
printf("%.2lf %.2lf\n",x[n/2],y[n/2]);
}
return 0;
}
本文介绍了一道经典的算法题目:在二维平面上找到一个点,使得该点到已知n个点的距离之和最小。文章通过示例代码展示了如何使用中位数来解决这个问题,并提供了完整的C++实现。
350

被折叠的 条评论
为什么被折叠?



