【题目链接】
【双倍经验链接】
【思路要点】
- 最小圆覆盖模板题。
- 时间复杂度\(O(N)\)。
【代码】
#include<bits/stdc++.h> using namespace std; const int MAXN = 100005; const long double eps = 1e-15; template <typename T> void chkmax(T &x, T y) {x = max(x, y); } template <typename T> void chkmin(T &x, T y) {x = min(x, y); } template <typename T> void read(T &x) { x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; x *= f; } template <typename T> void write(T x) { if (x < 0) x = -x, putchar('-'); if (x > 9) write(x / 10); putchar(x % 10 + '0'); } template <typename T> void writeln(T x) { write(x); puts(""); } struct point {long double x, y; } a[MAXN]; struct circle {point pos; long double r; }; point operator + (point a, point b) {return (point) {a.x + b.x, a.y + b.y}; } point operator - (point a, point b) {return (point) {a.x - b.x, a.y - b.y}; } point operator * (point a, long double b) {return (point) {a.x * b, a.y * b}; } long double operator * (point a, point b) {return a.x * b.y - a.y * b.x; } long double dist(point a, point b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } bool inside(point a, circle o) {return dist(a, o.pos) <= o.r + eps; } point unit(point a) { long double tmp = sqrt(a.x * a.x + a.y * a.y); return (point) {a.x / tmp, a.y / tmp}; } point inv(point a) {return (point) {-a.y, a.x}; } int main() { int n; read(n); for (int i = 1; i <= n; i++) scanf("%Lf%Lf", &a[i].x, &a[i].y); random_shuffle(a + 1, a + n + 1); circle now = (circle) {a[1], 0}; for (int i = 1; i <= n; i++) { if (inside(a[i], now)) continue; now = (circle) {a[i], 0}; for (int j = 1; j <= i - 1; j++) { if (inside(a[j], now)) continue; now = (circle) {(a[i] + a[j]) * 0.5, dist(a[i], a[j]) * 0.5}; for (int k = 1; k <= j - 1; k++) { if (inside(a[k], now)) continue; point b = (a[i] + a[j]) * 0.5; point c = b + inv(a[j] - a[i]); point d = (a[j] + a[k]) * 0.5; point e = d + inv(a[j] - a[k]); long double tmp = (d - b) * (e - b); long double tnp = (e - c) * (d - c); now.pos = (b * tnp + c * tmp) * (1 / (tmp + tnp)); now.r = dist(now.pos, a[i]); } } } printf("%.10Lf\n%.10Lf %.10Lf\n", now.r, now.pos.x, now.pos.y); return 0; }