牛牛战队的比赛地
https://ac.nowcoder.com/acm/contest/3006/B
题目要求为求最大距离最小值,联想到三分法(凹形序列?)
如果一个函数是若干个开口向上的二次函数的最大值 这个函数只能先减后增,那么这就只有一个凹形序列了
如果一个函数是若干个开口向下的二次函数的最小值 这个函数只能先增后减,那么这就只有一个凸形序列了
#pragma warning (disable :4996) #include <iostream> #include <cstdio> #include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1e9 + 7; const double eps = 1e-7; const int N = 1e5 + 10; int n; struct Point { int x, y; }a[N]; double Maxn(double x) { double maxn = 0; for (int i = 1; i <= n; i++) { double tmp = sqrt(a[i].y * a[i].y + (a[i].x - x) * (a[i].x - x)); if (maxn < tmp) maxn = tmp; } return maxn; } void solve() { double le = -10000, r = 10000; while (le + eps < r) { double lmid = le + (r - le) * (1.0 / 3), rmid = r - (r - le) * (1.0 / 3); if (Maxn(rmid) < Maxn(lmid)) le = lmid; else r = rmid; } printf("%.4lf\n", Maxn(le)); } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d %d", &a[i].x, &a[i].y); } solve(); }