define _CRT_SECURE_NO_WARNI NGS include iostream include cstdio includ

  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
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#define ll long long
#define eps 1e-8
#define all(x) x.begin(), x.end()
/*ОСТАВЬ НАДЕЖДУ, ВСЯК СЮДА ВХОДЯЩИЙ*/
const double pi = acos(-1.0);
using namespace std;
int I1 = 38;
int I2 = 38;
struct v2 {
double x, y;
v2() {}
v2(double _x, double _y) : x(_x), y(_y) {}
v2 operator -(const v2 &a) const { return v2(x - a.x, y - a.y); }
v2 operator +(const v2 &a) const { return v2(x + a.x, y + a.y); }
v2 operator *(double a) const { return v2(a * x, a * y); }
v2 operator /(double a) const { return v2(x / a, y / a); }
inline double sqlen() const { return x * x + y * y; }
bool operator <(const v2 a) const {
if (std::abs(x - a.x) < eps)
return y < a.y;
else
return x < a.x;
}
};
double dot(const v2& a, const v2& b) { return a.x * b.x + a.y * b.y; }
double cross(const v2& a, const v2& b) { return a.x * b.y - a.y * b.x; }
v2 ccw(const v2& a, double t) { return v2(a.x*cos(t) - a.y*sin(t), a.x*sin(t) + a.y*cos(t)); }
double distancePointLine(const v2& a, const v2& b, const v2& c) {
v2 ret = a + (b - a) * dot(c - a, b - a) / (b - a).sqlen();
return (c - ret).sqlen();
}
int l_id;
int r_id;
int n;
int bot_arc_size;
int top_arc_size;
v2 most_left_point = v2(1e7, 0);
v2 most_right_point = v2(-1e7, 0);
v2 g[10010];
int top_arc[10010] = { 0 };
int bot_arc[10010] = { 0 };
int mid[20020] = { 0 };
vector<int> modules(20000, 0);
double f(double x);
double find_y(const v2& a, const v2& b, double x);
double bot_y(double x);
double top_y(double x);
double find_radius(v2 x);
void init();
void test_generator();
int main(){
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
//freopen( "output.txt", "w", stdout);
#endif
//test_generator();
//return 0;
init();
double l = most_left_point.x;
double r = most_right_point.x;
for (int i = 0; i < I1; ++i) {
double x1 = l + (r - l) * 0.49;
double x2 = l + (r - l) * 0.51;
double r1 = f(x1);
double r2 = f(x2);
if (r1 < r2)
l = x1;
else
r = x2;
}
double answer = sqrt(f(l));
printf("%.4f", answer);
return 0;
}
double f(double x) {
double l = bot_y(x);
double r = top_y(x);
for (int i = 0; i < I2; ++i) {
double y1 = l + (r - l) * 0.49;
double y2 = l + (r - l) * 0.51;
double r1 = find_radius(v2(x, y1));
double r2 = find_radius(v2(x, y2));
if (r1 < r2)
l = y1;
else
r = y2;
}
return find_radius(v2(x, l));
}
double find_y(const v2& a, const v2& b, double x) {
if (std::abs(a.x - b.x) < 1e-9)
return std::max(a.y, b.y);
double K = (a.y - b.y) / (a.x - b.x);
double B = a.y - K * a.x;
return K*x + B;
}
double bot_y(double x) {
if (bot_arc_size == 2)
return find_y(g[bot_arc[0]], g[bot_arc[1]], x);
int l = 0;
int r = bot_arc_size - 1;
while (true) {
if (l == r - 1)
return find_y(g[bot_arc[l]], g[bot_arc[r]], x);
if (g[bot_arc[mid[l + r]]].x < x)
l = mid[l + r];
else
r = mid[l + r];
}
}
double top_y(double x) {
if (top_arc_size == 2)
return find_y(g[top_arc[0]], g[top_arc[1]], x);
int l = 0;
int r = top_arc_size - 1;
while (true) {
if (l == r - 1)
return find_y(g[top_arc[l]], g[top_arc[r]], x);
if (g[top_arc[mid[l + r]]].x < x)
l = mid[l + r];
else
r = mid[l + r];
}
}
double find_radius(v2 x) {
double ret = 1e100;
for (int i = 0; i < n; ++i) {
ret = std::min(distancePointLine(g[i], g[modules[i + 1]], x), ret);
}
return ret;
}
void init() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
modules[i] = i;
modules[i + n] = i;
}
for (int i = 0, k = 0; i < 2 * n; i += 2, k++) {
mid[i] = k;
mid[i + 1] = k;
}
for (int i = 0; i < n; ++i) {
int a, b;
scanf("%d%d", &a, &b);
g[i].x = a;
g[i].y = b;
if (g[i] < most_left_point) {
l_id = i;
most_left_point = g[i];
}
if (most_right_point < g[i]) {
r_id = i;
most_right_point = g[i];
}
}
for (int i = l_id; i <= (l_id < r_id ? r_id : r_id + n); ++i)
bot_arc[i - l_id] = modules[i];
for (int i = r_id; i <= (r_id < l_id ? l_id : l_id + n); ++i)
top_arc[i - r_id] = modules[i];
bot_arc_size = (l_id < r_id ? r_id : r_id + n) - l_id + 1;
top_arc_size = (r_id < l_id ? l_id : l_id + n) - r_id + 1;
reverse(top_arc, top_arc + top_arc_size);
}
void test_generator() {
int t = 10000;
v2 o1 = v2(0, 0);
v2 o2 = v2(1e6, 0);
for (double phi = 0, i = 0; phi <= 2 * pi && i < 10000; phi += 2 * pi / 10000) {
v2 c = ccw(o2, phi);
}
}