题解

我们先把所有点random_shuffle一下

然后对前i - 1个点计算一个最小圆覆盖,然后第i个点如果不在这个圆里,那么我们把这个点当成一个新的点,作为圆心,半径为0

从头枚举1 - i - 1,看看每个点在不在这个圆里,如果不在,那么就把新的点j,做一个圆经过i和j(就是i,j中点的作为圆心)

再枚举1 - j - 1,看看每个点在不在这个圆里,如果不在,那么新的点k,三点可以确定一个圆

写三个for就行

咦这不是\(n^3\)的吗

然而我们每个点只有\(\frac{3}{i}\)的概率被选上,复杂度是\(O(n)\)的

代码

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <cmath>
#include <bitset>
#include <queue>
#define enter putchar('\n')
#define space putchar(' ')
//#define ivorysi
#define pb push_back
#define mo 974711
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define MAXN 100005
#define eps 1e-12
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
res = 0;char c = getchar();T f = 1;
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 - '0' + c;
c = getchar();
}
res = res * f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) out(x / 10);
putchar('0' + x % 10);
}
struct Point {
db x,y;
Point(db _x = 0.0,db _y = 0.0) {
x = _x;y = _y;
}
friend Point operator + (const Point &a,const Point &b) {
return Point(a.x + b.x,a.y + b.y);
}
friend Point operator - (const Point &a,const Point &b) {
return Point(a.x - b.x,a.y - b.y);
}
friend Point operator * (const Point &a,const db &d) {
return Point(a.x * d,a.y * d);
}
friend db operator * (const Point &a,const Point &b) {
return a.x * b.y - a.y * b.x;
}
friend db dot(const Point &a,const Point &b) {
return a.x * b.x + a.y * b.y;
}
db norm() {
return sqrt(x * x + y * y);
}
}P[MAXN],C;
db R;
struct Seg {
Point a,b;
Seg(){}
Seg(Point _a,Point _b) {
a = _a;b = _b;
}
friend Point Cross_Point(const Seg &s,const Seg &t) {
db S1 = (s.a - t.a) * (t.b - t.a);
db S2 = (s.b - t.b) * (t.a - t.b);
return s.a + (s.b - s.a) * (S1 / (S1 + S2));
}
};
Point C_Point(Point a,Point b) {
return Point((a.x + b.x) * 0.5,(a.y + b.y) * 0.5);
}
int N;
void Solve() {
read(N);
db x,y;
for(int i = 1 ; i <= N ; ++i) {
scanf("%lf%lf",&x,&y);
P[i] = Point(x,y);
}
srand(20020421);
random_shuffle(P + 1,P + N + 1); C = P[1];
R = 0;
for(int i = 2 ; i <= N ; ++i) {
if((P[i] - C).norm() > R + eps) {
C = P[i];
R = 0;
for(int j = 1 ; j < i ; ++j) {
if((P[j] - C).norm() > R + eps) {
C = Point((P[i].x + P[j].x) * 0.5,(P[i].y + P[j].y) * 0.5);
R = (P[i] - C).norm();
for(int k = 1 ; k < j ; ++k) {
if((P[k] - C).norm() > R + eps) {
Point t1 = Point(P[j].y - P[k].y,P[k].x - P[j].x);
Point t2 = Point(P[i].y - P[k].y,P[k].x - P[i].x);
Point s1 = C_Point(P[k],P[j]);
Point s2 = C_Point(P[k],P[i]);
C = Cross_Point(Seg(s1,s1 + t1),Seg(s2,s2 + t2));
R = (P[k] - C).norm();
}
}
}
}
}
}
printf("%.10lf\n",R);
printf("%.10lf %.10lf\n",C.x,C.y);
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}
05-11 15:38