-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwelzl.cpp
More file actions
131 lines (114 loc) · 2.45 KB
/
Copy pathwelzl.cpp
File metadata and controls
131 lines (114 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
typedef pair<double,double>pdd;
const int N=1e5+10,M=1e5+10,INF=0x3f3f3f3f,MOD=1e9+7;
const double EPS=1e-8;
const double PI=acos(-1);
int n,m;
int dcmp(double x,double y){
if(fabs(x-y)<EPS)return 0;
else if(x<y)return -1;
else return 1;
}
struct Point{
double x,y;
Point(double x1=0,double y1=0){
x=x1,y=y1;
}
Point operator + (Point b){
return {x+b.x,y+b.y};
}
Point operator - (Point b){
return {x-b.x,y-b.y};
}
Point operator * (double b){
return {x*b,y*b};
}
Point operator / (double b){
return {x/b,y/b};
}
bool operator == (Point b){
return (!dcmp(x,b.x)&&!dcmp(y,b.y));
}
}po[N];
struct Vector{
double i,j;
Vector(double i1=0,double j1=0){
i=i1,j=j1;
}
Vector operator + (Vector b){
return {i+b.i,j+b.j};
}
Vector operator - (Vector b){
return {i-b.i,j-b.j};
}
Vector operator * (double b){
return {i*b,j*b};
}
Vector operator / (double b){
return {i/b,j/b};
}
}ve[N];
struct Circle{
Point p;
double r;
};
Point operator + (Point p,Vector v){
return {p.x+v.i,p.y+v.j};
}
double cross(Vector a,Vector b){
return a.i*b.j-b.i*a.j;
}
Vector getvector(Point p){
return {p.x,p.y};
}
Point rotate(Vector a,double b){
return {a.i*cos(b)+a.j*sin(b),-a.i*sin(b)+a.j*cos(b)};
}
double getdistance3(Point a,Point b){
double dx=a.x-b.x;
double dy=a.y-b.y;
return sqrt(dx*dx+dy*dy);
}
Point getintersection(Point p,Vector v,Point q,Vector w){
/* intersection of two vector */
Vector u=getvector(p)-getvector(q);
double t=cross(w,u)/cross(v,w);
return p+v*t;
}
pair<Point,Point> getnorm(Point a,Point b){
Point m={(a.x+b.x)/2,(a.y+b.y)/2};
return {m,rotate(getvector(b-a),PI/2)};
}
Circle getcircle(Point a,Point b,Point c){
auto u=getnorm(a,b),v=getnorm(a,c);
Point p=getintersection(u.first,getvector(u.second),v.first,getvector(v.second));
return {p,getdistance3(p,a)};
}
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%lf%lf",&po[i].x,&po[i].y);
}
random_shuffle(po,po+n);
Circle c({po[0],0});
for(int i=1;i<n;i++){
if(dcmp(c.r,getdistance3(c.p,po[i]))<0){
c={po[i],0};
for(int j=0;j<i;j++){
if(dcmp(c.r,getdistance3(c.p,po[j]))<0){
c={(po[i]+po[j])/2,getdistance3(po[i],po[j])/2};
for(int k=0;k<j;k++){
if(dcmp(c.r,getdistance3(c.p,po[k]))<0){
c=getcircle(po[i],po[j],po[k]);
}
}
}
}
}
}
printf("%.10lf\n",c.r);
printf("%.10lf %.10lf",c.p.x,c.p.y);
}