牛牛战队的比赛地-三分板子

链接:https://ac.nowcoder.com/acm/contest/3006/B
来源:牛客网
 

题目描述

由于牛牛战队经常要外出比赛,因此在全国各地建立了很多训练基地,每一个基地都有一个坐标(x,y)(x,y)(x,y)。

这周末,牛牛队又要出去比赛了,各个比赛的赛点都在xxx轴上。牛牛战队为了方便比赛,想找一个到达训练基地最大距离最小的地方作为比赛地。

这个问题对于牛牛战队太简单了,它就交给了你,你来帮他算一下~

输入描述:

 

输入数据第一行包含一个整数N(1≤N≤100 000)N(1 \leq N \leq 100\,000)N(1≤N≤100000),表示牛牛战队训练基地的数量。

接下来NNN行,每行包括222个整数x,y(−10 000≤x,y≤10 000)x,y(-10\,000 \leq x,y \leq 10\,000)x,y(−10000≤x,y≤10000),表示每一个训练基地的坐标。

输出描述:

 

输出一个小数,表示选择的比赛地距离各训练基地最大距离的最小值。

如果你的答案是aaa,标准答案是bbb,当∣a−b∣max(1,∣b∣)≤10−4\frac{|a-b|}{max(1,|b|)}\leq 10^{-4}max(1,∣b∣)∣a−b∣​≤10−4时,你的答案将被判定为正确。

示例1

输入

复制3 0 0 2 0 0 2

3
0 0
2 0
0 2

输出

复制2

2

说明

当在(0,0)(0,0)(0,0)比赛时,到三个训练基地的最大距离是222。可以证明这是最小值。
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define ll long long
#define pi acos(-1)
#define IOS ios::sync_with_stdio(false), cin.tie(0)
const double eps = 1e-9;
using namespace std;
const int maxn = 1e5+9;
struct node{
    double x, y;
}pp[maxn];
int n;
double check(double x) {
    double ans = 0.0;
    for(int i = 1;i <= n;++i) {
        ans = max(ans, sqrt((pp[i].x-x) * (pp[i].x-x) + pp[i].y*pp[i].y));
    }
    return ans;
}
int main() {
    scanf("%d", &n);
    for(int i = 1;i <= n;++i) {
        scanf("%lf%lf", &pp[i].x, &pp[i].y);
    }
    double l = -inf * 1.0, r = inf * 1.0 ;
    while(r - l > eps) {
        double lmid = l + (r - l) / 3.0;
        double rmid = r - (r - l) / 3.0;
        if(check(lmid) > check(rmid)) {
            l = lmid;
        }
        else {
            r = rmid;
        }
    }
    cout << check(l) << endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_43568078/article/details/105065442