Blog of RuSun

\begin {array}{c} \mathfrak {One Problem Is Difficult} \\\\ \mathfrak {Because You Don't Know} \\\\ \mathfrak {Why It Is Diffucult} \end {array}

P2533 [AHOI2012]信号塔

P2533 [AHOI2012]信号塔

最小圆覆盖模板。

查看代码
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int N = 1e6 + 10;
const double pi = acos(-1), eps = 1e-8;
int cmp(double a, double b)
{
if (a - b > eps)
return 1;
if (b - a > eps)
return -1;
return 0;
}
int sign(double a)
{
return cmp(a, 0);
}
struct Point
{
double x, y;
void input()
{
scanf("%lf%lf", &x, &y);
}
bool operator<(const Point &_) const
{
int t = cmp(x, _.x);
if (t == 1)
return false;
if (t == -1)
return true;
return y < _.y;
}
Point operator+(const Point &_) const
{
return (Point){x + _.x, y + _.y};
}
Point operator-(const Point &_) const
{
return (Point){x - _.x, y - _.y};
}
Point operator*(const double &t) const
{
return (Point){x * t, y * t};
}
Point operator/(const double &t) const
{
return (Point){x / t, y / t};
}
};
double dot(Point a, Point b)
{
return a.x * b.x + a.y * b.y;
}
double cross(Point x, Point y)
{
return x.x * y.y - y.x * x.y;
}
double area(Point a, Point b, Point c)
{
return cross(b - a, c - a);
}
double Len(Point a)
{
return sqrt(dot(a, a));
}
double Angle(Point a, Point b)
{
return acos(dot(a, b) / Len(a) / Len(b));
}
double Distance(Point a, Point b)
{
double dx = a.x - b.x, dy = a.y - b.y;
return sqrt(dx * dx + dy * dy);
}
Point rotate(Point a, double theta)
{
return (Point){a.x * cos(theta) - a.y * sin(theta), a.x * sin(theta) + a.y * cos(theta)};
}
struct Segment
{
Point x, y;
void input()
{
x.input(), y.input();
}
double Angle()
{
return atan2(y.y - x.y, y.x - x.x);
}
bool operator<(Segment &_)
{
double a = Angle(), b = _.Angle();
if (!cmp(a, b))
return sign(area(x, y, _.y)) == -1;
return a < b;
}
int onSegment(Point p)
{
return -sign(area(x, y, p));
}
double DistanceToLine(Point p)
{
Point u = y - x, v = p - x;
return abs(cross(v, u) / Len(v));
}
double DistanceToSegment(Point p)
{
if (!cmp(x.x, y.x) && cmp(x.y, y.y))
return Len(p - x);
Point u = y - x, v = p - x, w = p - y;
if (sign(dot(u, v)) == -1)
return Len(v);
if (sign(dot(v, w)) == 1)
return Len(u);
return DistanceToLine(p);
}
Point Projection(Point p)
{
Point u = y - x;
return x + u * (dot(u, p - x) / dot(u, u));
}
};
Segment Vertical(Point a, Point b)
{
return (Segment){(a + b) / 2, rotate(b - a, pi / 2)};
}
Point Intersection(Segment a, Segment b)
{
Point u = a.x - b.x;
double t = cross(b.y, u) / cross(a.y, b.y);
return a.x + a.y * t;
}
bool ExistIntersection(Segment a, Segment b)
{
return sign(cross(a.y - a.x, b.x - a.x)) * sign(cross(a.y - a.x, b.y - a.x)) <= 0 && sign(cross(b.y - b.x, a.x - b.x)) * sign(cross(b.y - b.x, a.y - b.x)) <= 0;
}
struct Circle
{
Point p;
double r;
};
Circle circle(Point a, Point b, Point c)
{
Segment u = Vertical(a, b), v = Vertical(a, c);
Point p = Intersection(u, v);
return {p, Distance(p, a)};
}
struct Polygon
{
int n;
Point p[N];
void input()
{
scanf("%d", &n);
for (int i = 0; i < n; i++)
p[i].input();
}
void insert(Point a)
{
p[n++] = a;
}
double PolygonArea()
{
double res = 0;
for (int i = 1; i < n; i++)
res += area(p[0], p[i], p[i + 1]);
return res / 2;
}
double PolygonCircumference()
{
double res = 0;
for (int i = 0; i + 1 < n; i++)
res += Distance(p[i], p[i + 1]);
return res;
}
void ConvexHull(int &cnt, Point *ans)
{
static bool vis[N];
sort(p, p + n);
static int top = 0, stk[N];
stk[++top] = 0, stk[++top] = 1;
for (int i = 2; i < n; i++)
{
while (top >= 2)
{
int t = sign(area(p[stk[top]], p[stk[top - 1]], p[i]));
if (t == -1)
vis[stk[top--]] = false;
else if (t == 0)
top--;
else
break;
}
vis[stk[++top] = i] = true;
}
vis[0] = false;
for (int i = n - 1; i >= 0; i--)
{
if (vis[i])
continue;
while (top >= 2 && sign(area(p[stk[top]], p[stk[top - 1]], p[i])) == -1)
top--;
vis[stk[++top] = i] = true;
}
cnt = 0;
for (int i = 1; i < top; i++)
ans[cnt++] = p[stk[i]];
}
Circle cover()
{
random_shuffle(p, p + n);
Circle c;
c.p = p[0];
c.r = 0;
for (int i = 1; i < n; i++)
{
if (cmp(c.r, Distance(c.p, p[i])) >= 0)
continue;
c.p = p[i];
c.r = 0;
for (int j = 0; j < i; j++)
{
if (cmp(c.r, Distance(c.p, p[j])) >= 0)
continue;
c.p = (p[i] + p[j]) / 2;
c.r = Distance(p[i], p[j]) / 2;
for (int k = 0; k < j; k++)
{
if (cmp(c.r, Distance(c.p, p[k])) >= 0)
continue;
c = circle(p[i], p[j], p[k]);
}
}
}
return c;
}
};
void HalfPlaneIntersection(int idx, Segment *l, int &cnt, Point *ans)
{
sort(l, l + idx);
static int hd = 0, tl = -1, q[N];
for (int i = 0; i < idx; i++)
{
if (i && !cmp(l[i].Angle(), l[i - 1].Angle()))
continue;
while (hd + 1 <= tl && l[i].onSegment(Intersection(l[q[tl - 1]], l[q[tl]])) >= 0)
tl--;
while (hd + 1 <= tl && l[i].onSegment(Intersection(l[q[hd + 1]], l[q[hd]])) >= 0)
hd++;
q[++tl] = i;
}
while (hd + 1 <= tl && l[q[hd]].onSegment(Intersection(l[q[tl - 1]], l[q[tl]])) >= 0)
tl--;
while (hd + 1 <= tl && l[q[tl]].onSegment(Intersection(l[q[hd + 1]], l[q[hd]])) >= 0)
hd++;
q[++tl] = q[hd];
for (int i = hd; i < tl; i++)
ans[cnt++] = Intersection(l[q[i]], l[q[i + 1]]);
}
int main()
{
Polygon p;
p.input();
Circle c = p.cover();
printf("%.2lf %.2lf %.2lf", c.p.x, c.p.y, c.r);
return 0;
}