# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
59374 | Benq | 2circles (balkan11_2circles) | C++14 | 3192 ms | 8464 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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];
template<class T> istream& operator>> (istream& is, complex<T>& p) {
T value;
is >> value; p.real(value);
is >> value; p.imag(value);
return is;
}
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); }
cd line(cd a, cd b, cd c, cd d) {
ld x = area(a,b,c), y = area(a,b,d);
return (x*d-y*c)/(x-y);
}
pair<cd,cd> trans(pair<cd,cd> a, ld mid) {
cd z = (a.s-a.f)/abs(a.s-a.f)*cd(0,1)*mid;
a.f += z, a.s += z;
return a;
}
cd inter(pair<cd,cd> a, pair<cd,cd> b, ld mid) {
a = trans(a,mid);
b = trans(b,mid);
return line(a.f,a.s,b.f,b.s);
}
bool bad(pair<cd,cd> a, pair<cd,cd> b, pair<cd,cd> c, ld mid) {
// exit(0);
cd x = inter(a,b,mid);
cd y = inter(b,c,mid);
cd z = (y-x)/(b.s-b.f);
return z.real() <= 0;
}
ld dia(vcd v) {
ld ans = 0;
int ind = 1;
F0R(i,sz(v)) {
while (abs(area(v[i],v[(i+1)%sz(v)],v[ind])) < abs(area(v[i],v[(i+1)%sz(v)],v[(ind+1)%sz(v)]))) {
ans = max(ans,abs(v[ind]-v[i]));
ind = (ind+1)%sz(v);
}
}
return ans;
}
bool test(ld mid) {
vector<pair<cd,cd>> st;
F0R(i,N) {
pair<cd,cd> nex = {p[i%N],p[(i+1)%N]};
while (sz(st) >= 2 && bad(st[sz(st)-2],st.back(),nex,mid)) st.pop_back();
st.pb(nex);
}
if (sz(st)) {
auto a = st.front();
while (sz(st) >= 2 && bad(st[sz(st)-2],st.back(),a,mid)) st.pop_back();
}
if (sz(st) <= 2) return 0;
vcd v;
F0R(i,sz(st)) v.pb(inter(st[i],st[(i+1)%sz(st)],mid));
//cout << dia(v) << " " << 2*mid << "\n";
return dia(v) >= 2*mid;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> N;
F0R(i,N) cin >> p[i]; // counterclockwise order
//cout << test(68575);
//exit(0);
while (hi-lo > (1e-5)) {
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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |