【JZOJ3877】寻址

problem

Description

Input

第一行包括一个整数n。
第二行到第n+1行,每行包括两个整数,代表每一个基站的坐标。

Output

第一行包括两个实数x,y,代表住址的坐标。
精确到小数点后6位。

Sample Input

输入1:
3
1 4
2 1
3 4
输入2:
6
2 2
2 5
3 9
4 7
5 1
5 7

Sample Output

输出1:
2 3
【样例解释1】
(2,2)的不便度为5,可以证明平面上的其他位置均不会更优。

输出2:
3.969832 6.763417
【样例解释2】
这里有不止一个解,(3.969832,6.763417)是其中之一。

Data Constraint


analysis

  • 其实这个距离叫做切比雪夫距离

  • 曼哈顿距离的转换公式就不多说了, ( x , y ) 变成 ( x + y 2 , x y 2 ) 就是曼哈顿距离了

  • 排序后贪心取中点


code

#include<stdio.h>
#include<algorithm>
#define MAXN 10001

using namespace std;

double x[MAXN],y[MAXN],xx,yy;
int n;

int main()
{
    //freopen("readin.txt","r",stdin);
    scanf("%d",&n);
    for (int i=1;i<=n;i++) 
    {
        int xx,yy;
        scanf("%d%d",&xx,&yy);
        x[i]=1.0*(xx+yy)/2,y[i]=1.0*(xx-yy)/2;
    }
    sort(x+1,x+n+1),sort(y+1,y+n+1);
    if (n&1)xx=x[(n+1)/2],yy=y[(n+1)/2];
    else xx=(x[n/2]+x[n/2+1])/2,yy=(y[n/2]+y[n/2+1])/2;
    printf("%.6lf %.6lf",xx+yy,xx*2-xx-yy);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/enjoy_pascal/article/details/80586099