标签:long 覆盖 class 数据 一点 tchar struct its 前置
给出N个点,让你画一个最小的包含所有点的圆。
先给出点的个数N,2<=N<=100000,再给出坐标Xi,Yi.(-10000.0<=xi,yi<=10000.0)
输出圆的半径,及圆心的坐标,保留10位小数
6
8.0 9.0
4.0 7.5
1.0 2.0
5.1 8.7
9.0 2.0
4.5 1.0
5.0000000000
5.0000000000 5.0000000000
none
#include <bits/stdc++.h>
#define _ 0
#define LL long long
inline LL in() {
LL x = 0, f = 1; char ch;
while(!isdigit(ch = getchar()))(ch == '-') && (f = -f);
while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
return x * f;
}
const int maxn = 1e5 + 10;
const double eps = 1e-14;
struct node {
double x, y;
node(double x = 0, double y = 0)
:x(x), y(y) {}
double mod() {
return sqrt(x * x + y * y);
}
friend node operator - (const node &a, const node &b) {
return node(a.x - b.x, a.y - b.y);
}
friend node operator + (const node &a, const node &b) {
return node((a.x + b.x) / 2.0, (a.y + b.y) / 2.0);
}
}e[maxn];
int n;
void circle(node a, node b, node c, node &o, double &r) {
node ab = b - a, bc = c - b, mid1 = a + b, mid2 = b + c;
double A1 = ab.x, B1 = ab.y, A2 = bc.x, B2 = bc.y;
double C1 = A1 * mid1.x + B1 * mid1.y, C2 = A2 * mid2.x + B2 * mid2.y;
o = node((C2 * B1 - C1 * B2) / (A2 * B1 - A1 * B2), (C2 * A1 - C1 * A2) / (B2 * A1 - B1 * A2));r = (o - a).mod();
}
void work() {
node o = e[1];
double r = 0;
for(int i = 2; i <= n; i++)
if((e[i] - o).mod() - r > eps) {
o = e[i], r = 0;
for(int j = 1; j <= i - 1; j++)
if((e[j] - o).mod() - r > eps) {
o = e[i] + e[j];
r = (o - e[i]).mod();
for(int k = 1; k <= j - 1; k++)
if((e[k] - o).mod() - r > eps)
circle(e[i], e[j], e[k], o, r);
}
}
printf("%.10f\n%.10f %.10f", r, o.x, o.y);
}
int main() {
n = in();
for(int i = 1; i <= n; i++) scanf("%lf%lf", &e[i].x, &e[i].y);
work();
return 0;
}
标签:long 覆盖 class 数据 一点 tchar struct its 前置
原文地址:https://www.cnblogs.com/olinr/p/10187221.html