2020 cattle off winter training camp algorithm base 5 B team match to beef

https://ac.nowcoder.com/acm/contest/3006/B

Title Description

Because beef clan often away matches, so a lot of the country to establish training bases, each base has a coordinate (X, y).

This weekend, Taurus team have to go out the match, match point in each game of xthe shaft. Taurus team for the convenience of the game, looking for a training base to reach the maximum and minimum distances as a place to race.

The problem for the Taurus team too simple, it is up to you, you to help him count ~

Thinking

Written on the solution to a problem is one-third, two points can also write, I was half written, he said the following is a dichotomous thinking.

Half of the smallest maximum distance, the first venue in a certain xaxis, for each training base, if the distance is the same venue dist, the venue must be in it for the center to a radius of distthe circle, that is round and axis xtwo intersections, two minutes or less when the distance distis the legal, that is, as long as the space between two valid coordinates. This record can be considered coordinate space, we ask for more training base this intersection coordinate range, if the intersection is not empty, then the distlegitimate, if this represents the intersection is empty distis not feasible. Because demand from the need to square root, and therefore need special value judgment about the root number is positive, not positive direct illegal.

/*************************************************************************
    > File Name: B.cpp
    > Author: amoscykl
    > Mail: [email protected]
    > Created Time: 2020年02月13日 星期四 14时52分21秒
 ************************************************************************/
 
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int inf = 0x3f3f3f3f;
int px[N], py[N];
int n;
#define eps 1e-8
bool check(double x){
    double xl, xr;
    double temp = x * x - py[1] * py[1] * 1.0;
    if (temp < 0)return false;
    temp = sqrt(temp);
    xl = px[1] * 1.0 - temp;
    xr = px[1] * 1.0 + temp;
    for (int i = 2; i <= n; i++){
        temp = x * x - py[i] * py[i] * 1.0;
        if (temp < 0)return false;
        temp = sqrt(temp);
        double txl = px[i] * 1.0 - temp;
        double txr = px[i] * 1.0 + temp;
        if (xl > txr || xr < txl){
            // 没有交集
            return false;
        }
        else{
            xl = max(xl, txl);
            xr = min(xr, txr);
        }
    }
    return true;
}
int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++){
        scanf("%d %d", px + i, py + i);
    }
    double l = 0.0;
    double r = inf * 1.0;
    double res = -1;
    while (r - l > eps){
        double mid = (l + r) / 2.0;
        if (check(mid)){
            res = mid;
            r = mid;
        }
        else l = mid;
    }
    printf("%.6lf\n", res);
    return 0;
}

 

Published 204 original articles · won praise 13 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_43701790/article/details/104308735