#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
const int MAXN = 50005;
const double eps = 1e-6;
typedef pair<double, double> pi;
double ccw(pi a, pi b, pi c){
double dx1 = b.first - a.first;
double dy1 = b.second - a.second;
double dx2 = c.first - a.first;
double dy2 = c.second - a.second;
return dx1 * dy2 - dy1 * dx2;
}
namespace hpi{
bool z(double x){ return fabs(x) < eps; }
struct line{
double a, b, c;
bool operator<(const line &l)const{
bool flag1 = pi(a, b) > pi(0, 0);
bool flag2 = pi(l.a, l.b) > pi(0, 0);
if(flag1 != flag2) return flag1 > flag2;
double t = ccw(pi(0, 0), pi(a, b), pi(l.a, l.b));
return z(t) ? c * hypot(l.a, l.b) < l.c * hypot(a, b) : t > 0;
}
pi slope(){ return pi(a, b);}
};
pi cross(line a, line b){
double det = a.a * b.b - b.a * a.b;
return pi((a.c * b.b - a.b * b.c) / det, (a.a * b.c - a.c * b.a) / det);
}
bool bad(line a, line b, line c){
pi crs = cross(a, b);
return crs.first * c.a + crs.second * c.b >= c.c - eps;
}
bool solve(vector<line> v, vector<pi> &solution){ // ax + by <= c;
// sort(v.begin(), v.end());
deque<line> dq;
for(auto &i : v){
if(!dq.empty() && ccw(pi(0, 0), dq.back().slope(), i.slope()) <= eps) return false;
while(dq.size() >= 2 && bad(dq[dq.size()-2], dq.back(), i)) dq.pop_back();
dq.push_back(i);
}
while(dq.size() > 2 && bad(dq[dq.size()-2], dq.back(), dq[0])) dq.pop_back();
while(dq.size() > 2 && bad(dq.back(), dq[0], dq[1])) dq.pop_front();
vector<pi> tmp;
for(int i=0; i<dq.size(); i++){
line cur = dq[i], nxt = dq[(i+1)%dq.size()];
if(ccw(pi(0, 0), cur.slope(), nxt.slope()) <= eps) return false;
tmp.push_back(cross(cur, nxt));
}
solution = tmp;
return true;
}
};
int x[MAXN], y[MAXN], n;
pi sub(vector<pi> &v, int x, int y){
x %= v.size(), y %= v.size();
return pi(v[y].first - v[x].first, v[y].second - v[x].second);
}
double dist(pi a, pi b){
return hypot(b.second - a.second, b.first - a.first);
}
bool trial(double t){
vector<hpi::line> v;
for(int i=0; i<n; i++){
double a = y[i+1] - y[i];
double b = x[i] - x[i+1];
double c = a * x[i] + b * y[i] - hypot(a, b) * t;
v.push_back({a, b, c});
}
vector<pi> w;
if(!hpi::solve(v, w)){
return false;
}
int p = 0;
double ret = 0;
for(int i=0; i<w.size(); i++){
while(ccw(pi(0, 0), sub(w, p+1, p), sub(w, i, i+1)) > -eps){
ret = max(ret, dist(w[i], w[p]));
p = (p+1)%w.size();
ret = max(ret, dist(w[i], w[p]));
}
ret = max(ret, dist(w[i], w[p]));
}
return ret >= 2 * t;
}
int main(){
scanf("%d",&n);
for(int i=0; i<n; i++){
scanf("%d %d",&x[i],&y[i]);
}
x[n] = x[0], y[n] = y[0];
double s = 0, e = 1e7;
for(int i=0; i<50; i++){
double m = (s+e)/2;
if(trial(m)) s = m;
else e = m;
}
printf("%.3f",s);
}
Compilation message
2circles.cpp: In function 'bool hpi::solve(std::vector<hpi::line>, std::vector<std::pair<double, double> >&)':
2circles.cpp:48:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<dq.size(); i++){
^
2circles.cpp: In function 'bool trial(double)':
2circles.cpp:83:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<w.size(); i++){
^
2circles.cpp: In function 'int main()':
2circles.cpp:95:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
^
2circles.cpp:97:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&x[i],&y[i]);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2424 KB |
Output is correct |
2 |
Correct |
0 ms |
2424 KB |
Output is correct |
3 |
Correct |
0 ms |
2424 KB |
Output is correct |
4 |
Correct |
0 ms |
2424 KB |
Output is correct |
5 |
Correct |
9 ms |
2692 KB |
Output is correct |
6 |
Correct |
103 ms |
3860 KB |
Output is correct |
7 |
Correct |
69 ms |
3448 KB |
Output is correct |
8 |
Correct |
53 ms |
3532 KB |
Output is correct |
9 |
Correct |
226 ms |
4856 KB |
Output is correct |
10 |
Incorrect |
383 ms |
6912 KB |
Output isn't correct |