P1742 smallest circle coverage
Title Description
Given N points, lets you draw a circle that contains the smallest of all points.
Input Format
The number of points given to N, 2 <= N <= 100000, then given the coordinates Xi, Yi. (- 10000.0 <= xi, yi <= 10000.0)
Output Format
Output radius of the circle, and the coordinates of the center, to retain 10 decimal
Sample input and output
Input # 1
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
Output # 1
5.0000000000
5.0000000000 5.0000000000
Description / Tips
5.00 5.00 5.0
Random number processing complexity is O (n)
The first point as a center;
The second point and the midpoint of a center point connection is positioned a distance of the diameter;
The third point to the first two points and three points given circle;
#pragma GCC optimize(2)
#pragma GCC optimize(3, "Ofast", "inline")
#include<bits/stdc++.h>//O(n)
#define ll long long
#define met(a, x) memset(a,x,sizeof(a))
#define inf 0x3f3f3f3f
#define ull unsigned long long
using namespace std;
const double eps = 1e-12;
struct node {
double x, y;
} s[500005];
node o;//圆心坐标
double ri;//半径
doubleDIS (Node A, Node B) {
return sqrt ((AX - BX) * (AX - BX) + (AY - by) * (AY - by));
}
void GETR (Node P1, Node P2, Node P3) { // three triangular points required positions and radii of
Double A, B, C, D, E, F;
A = p2.y - p1.y;
B = p3.y - p1.y;
C = P2.x - P1.x;
D = p3.x - P1.x;
F = + p3.y p3.x p3.x * * p3.y - P1.x P1.x * - * p1.y p1.y;
E * + p2.y P2.x P2.x = p2.y * - * P1.x P1.x - p1.y * p1.y;
OX = (F * A - B * E) / ( 2 * A * d -2 * b * c);
o.y = (d * e - c * f) / (2 * a * d - 2 * b * c);
ri = dis(o, p1);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> s[i].x >> s[i].y;
}
random_shuffle(s + 1, s + n + 1);
o = s[1];
ri = 0;
for (int i = 2; i <= n; i++) {
if (dis(s[i], o) > ri + eps) {
o = s[i];
ri = 0;//第一个点为圆心
for (int j = 1; j < i; j++) {
if (dis(o, s[j]) > ri + eps) {
o.x = (s[i].x + s[j].x) / 2;
o.y = (S [I] .y + S [J] .y) / 2 ;
RI = DIS (O, S [J]); // first point and the second point is the midpoint of the center, a distance of the diameter
for ( int K = . 1 ; K <J; K ++ ) {
IF (DIS (O, S [K])> RI + EPS) {
GETR (S [I], S [J], S [K]); / / three - point circle
}
}
}
}
}
}
COUT << fixed << setPrecision ( 10 ) RI << << endl;
COUT <<fixed << setprecision(10) << o.x << ' ' << fixed << setprecision(10) << o.y << endl;
return 0;
}