Title Description
Because beef clan often away matches, so a lot of the country to establish training bases, each base has a coordinate
.
This weekend, Taurus team have to go out the match, match point in each game
-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 , it represents the number of beef team training base.
Next rows, each row comprising integers , 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 , the standard answer is , when when your answer will be judged to be true.
Entry
3
0 0
2 0
0 2
Export
2
Explanation
This standing game, the maximum distance is three training base . It may prove to be the minimum.
answer
- Note that all points are
-axis (
md, did not pay attention, most thought it was a two-dimensional plane) - Now in -axis, it is easy to determine, for the function 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;
}