2020 cattle off the base algorithm winter training camp 5.B-- beef clan match the [one-third]

Topic Portal


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 ) (X, y) .
This weekend, Taurus team have to go out the match, match point in each game x x -axis. 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 ~


Enter a description:

The first line of input data contains an integer N ( 1 N 100 000 ) N (1 \ leq N \ leq 100 \, 000) , it represents the number of beef team training base.

Next N N rows, each row comprising 2 2 integers x , y ( 10 000 x , y 10 000 ) x, y (-10 \, 000 \? x, and \? 10 \, 000) , it represents the coordinates of each training base.


Output Description:

Output a decimal, represents the minimum value of the maximum distance from each selected to match training base.

If your answer is a a , the standard answer is b b , when a b m a x ( 1 , b ) 1 0 4 \frac{|a-b|}{max(1,|b|)}\leq 10^{-4} when your answer will be judged to be true.


Entry

3
0 0
2 0
0 2


Export

2


Explanation

This standing ( 0 , 0 ) (0,0) game, the maximum distance is three training base 2 2 . It may prove to be the minimum.


answer

  • Note that all points are X X -axis (md, did not pay attention, most thought it was a two-dimensional plane)
  • Now in X X -axis, it is easy to determine, for the function f ( x ) = min { max { d i s ( x , i ) } ( i [ 1 , n ] ) } f(x)=\min\{\max\{dis(x,i)\}(i\in[1,n])\} is a concave function, the most value, the third process can obviously
  • Note the precision control, or will TLE

AC-Code

#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e5 + 7;
const double eps = 1e-5;
struct Node {
	double x, y;
}a[maxn];
int n;
double check(double x) {
	double max_dis = 0;
	for (int i = 0; i < n; ++i) {
		double t = sqrt(a[i].y * a[i].y + (a[i].x - x) * (a[i].x - x));
		if (t > max_dis)	max_dis = t;
	}
	return max_dis;
}
double search(double low, double high) {
	while (low + eps < high) { // 控制精度,符合题意即可退出
		double mid = (low + high) / 2;
		double midmid = (mid + high) / 2;
		if (check(mid) < check(midmid))
			high = midmid;
		else
			low = mid;
	}
	return check(low);
}
int main() {
	while (cin >> n) {
		for (int i = 0; i < n; ++i)
			cin >> a[i].x >> a[i].y;
		printf("%.5f\n", search(-1e4, 1e4));
	}
	return 0;
}
Published 180 original articles · won praise 111 · views 10000 +

Guess you like

Origin blog.csdn.net/Q_1849805767/article/details/104301255