Submission #59353

#TimeUsernameProblemLanguageResultExecution timeMemory
59353Benq2circles (balkan11_2circles)C++14
10 / 100
4051 ms4468 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef complex<ld> cd; typedef pair<int, int> pi; typedef pair<ll,ll> pl; typedef pair<ld,ld> pd; typedef vector<int> vi; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef vector<cd> vcd; template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; #define FOR(i, a, b) for (int i=a; i<(b); i++) #define F0R(i, a) for (int i=0; i<(a); i++) #define FORd(i,a,b) for (int i = (b)-1; i >= a; i--) #define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--) #define sz(x) (int)(x).size() #define mp make_pair #define pb push_back #define f first #define s second #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() const int MOD = 1000000007; const ll INF = 1e18; const int MX = 100001; typedef pair<cd,ld> circ; int N; ld lo = 0, hi = 1e8; cd p[50000]; bool overlap(circ a, circ b) { return abs(a.f-b.f) < a.s+b.s; } template<class T> istream& operator>> (istream& is, complex<T>& p) { T value; is >> value; p.real(value); is >> value; p.imag(value); return is; } cd reflect(cd p, cd a, cd b) { return a+conj((p-a)/(b-a))*(b-a); } cd proj(cd p, cd a, cd b) { return (p+reflect(p,a,b))/(ld)2; } bool obtuse(cd a, cd b, cd c) { cd z = (a-b)/(c-b); return z.real() < 0; } ld dist(cd a, cd b, cd c) { // cout << "A\n"; if (obtuse(a,b,c)) return abs(a-b); // cout << "B " << a << " " << c << "\n"; if (obtuse(a,c,b)) return abs(a-c); // cout << "C\n"; return abs(a-proj(a,b,c)); } ld cross(cd a, cd b) { return (conj(a)*b).imag(); } ld area(cd a, cd b, cd c) { return cross(b-a,c-a); } int sgn(ld x) { if (x > 0) return 1; if (x == 0) return 0; return -1; } ld side(cd a, cd b, cd c) { return sgn(area(a,b,c)); } bool ok(circ x) { F0R(i,N) { if (side(x.f,p[i],p[(i+1)%N]) != side(p[(i+N-1)%N],p[i],p[(i+1)%N])) return 0; // cout << x.f << " " << p[i] << " " << p[(i+1)%N] << " " << dist(x.f,p[i],p[(i+1)%N]) << "\n"; // cout << obtuse(x.f,p[i],p[(i+1)%N]) << "\n"; if (dist(x.f,p[i],p[(i+1)%N]) < x.s-(1e-9)) return 0; } return 1; } circ genCirc(int i, ld rad) { ld a = arg(p[(i+1)%N]-p[i]); ld b = arg(p[(i+N-1)%N]-p[i]); cd offset; while (b <= a) b += 2*M_PIl; if (b > a+M_PIl) while (a <= b) a += M_PIl; offset = polar((ld)1,(a+b)/2); ld dis = abs(offset-proj(offset,cd(0,0),p[(i+N-1)%N]-p[i])); offset *= rad/dis; return {p[i]+offset,rad}; } bool test(ld mid) { vector<circ> v; F0R(i,N) { circ x = genCirc(i,mid); if (ok(x)) { // cout << x.f.real() << " " << x.f.imag() << " " << x.s << "\n"; v.pb(x); } } F0R(i,sz(v)) FOR(j,i+1,sz(v)) if (!overlap(v[i],v[j])) return 1; return 0; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> N; F0R(i,N) cin >> p[i]; while (hi-lo > (1e-4)) { ld mid = (lo+hi)/2; if (test(mid)) lo = mid; else hi = mid; } cout << fixed << setprecision(3) << (lo+hi)/2; } /* Look for: * the exact constraints (multiple sets are too slow for n=10^6 :( ) * special cases (n=1?) * overflow (ll vs int?) * array bounds */
#Verdict Execution timeMemoryGrader output
Fetching results...