QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#380638 | #5106. Islands from the Sky | UFRJ | AC ✓ | 445ms | 4704kb | C++14 | 4.6kb | 2024-04-07 07:25:36 | 2024-04-07 07:25:40 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
using lint = int64_t;
#define PI acos(-1.0)
template<class T> int sgn(T x) { return (x > 0) - (x < 0); }
template<class T>
struct Point {
typedef Point P;
T x, y;
explicit Point(T x = 0, T y = 0) : x(x), y(y) { }
bool operator<(P p) const { return tie(x, y) < tie(p.x, p.y); }
bool operator==(P p) const { return tie(x, y) == tie(p.x, p.y); }
P operator+(P p) const { return P(x+p.x, y+p.y); }
P operator-(P p) const { return P(x-p.x, y-p.y); }
P operator*(T d) const { return P(x*d, y*d); }
P operator/(T d) const { return P(x/d, y/d); }
T dot(P p) const { return x*p.x + y*p.y; }
T cross(P p) const { return x*p.y - y*p.x; }
T cross(P a, P b) const { return (a-*this).cross(b-*this); }
T dist2() const {return x*x + y*y; }
T dist() const {return sqrt((double) dist2()); }
double angle() const { return atan2(y, x); }
};
using P = Point<double>;
double segDist(P &s, P &e, P &p) {
if(s == e) return (p-s).dist();
auto d = (e-s).dist2(), t = min(d, max(.0, (p-s).dot(e-s)));
return ((p-s)*d-(e-s)*t).dist() / d;
}
template<class P> bool onSegment(P s, P e, P p) {
return p.cross(s, e) == 0 && (s - p).dot(e - p) <= 0;
}
template<class P>
bool inPolygon(vector<P> &p, P a, bool strict = true) {
int cnt = 0, n = p.size();
for(int i = 0; i < n; ++i) {
P q = p[(i+1) % n ];
if(onSegment(p[i], q, a)) return !strict;
cnt ^= ((a.y < p[i].y) - (a.y < q.y)) * a.cross(p[i], q) > 0;
}
return cnt;
}
template<class P>
int sideOf(P s, P e, P p) { return sgn(s.cross(e, p)); }
template<class P>
int sideOf(const P &s, const P &e, const P &p, double eps) {
auto a = (e-s).cross(p-s);
double l = (e-s).dist() * eps;
return (a > l) - (a < -l);
}
bool inHull(const vector<P> &l, P p, bool strict = true) {
int a = 1, b = l.size() - 1, r = !strict;
if(l.size() < 3) return r && onSegment(l[0], l.back(), p);
if(sideOf(l[0], l[a], l[b]) > 0) swap(a, b);
if(sideOf(l[0], l[a], p) >= r || sideOf(l[0], l[b], p) <= -r)
return false;
while(abs(a - b) > 1) {
int c = (a + b) / 2;
(sideOf(l[0], l[c], p) > 0 ? b : a) = c;
}
return sgn(l[a].cross(l[b], p)) < r;
}
int n, m;
vector<vector<P>> islands;
vector<pair<tuple<int,int,int>, tuple<int,int,int>>> airplanes;
bool test_angle(double angle) {
vector<vector<P>> traps;
int x1, x2, y1, y2, z1, z2;
for(auto [from, to] : airplanes) {
tie(x1, y1, z1) = from;
tie(x2, y2, z2) = to;
double dist1 = tan(angle * PI / 180) * z1;
double dist2 = tan(angle * PI / 180) * z2;
P s = P(x1, y1);
P e = P(x2, y2);
P aux = (e - s)/ (e - s).dist();
P dir = P(-aux.y, aux.x);
// cout << angle << " " << dist1 << " " << dist2 << endl;
vector<P> poly = {s + dir * dist1, s - dir * dist1, e - dir * dist2, e + dir * dist2};
// cout << "Poly: " << endl;
// for(auto &i : poly) {
// cout << i.x << " " << i.y << endl;
// }
traps.push_back(poly);
}
vector<bool>w(n);
// cout << "Angle: " << angle << endl;
for(int i=0;i<n;i++){
for(auto& poly : traps){
int cnt = 0;
for(auto& pnt : islands[i]){
cnt += inPolygon(poly, pnt);
// cout << i << " " << pnt.x << " " << pnt.y << " " << inHull(poly, pnt) << endl;
}
if(cnt == (int) islands[i].size()){
w[i] = true;
break;
}
}
}
bool ok = true;
for(int i = 0; i < n; i++) {
// cout << w[i] << " ";
ok &= w[i];
}
return ok;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> m;
islands.resize(n);
for(int i = 0, isize, x, y; i < n; i++) {
cin >> isize;
for(int j = 0; j < isize; j++) {
cin >> x >> y;
islands[i].push_back(P(x, y));
}
}
for(int i = 0, x1, x2, y1, y2, z1, z2; i < m; i++) {
cin >> x1 >> y1 >> z1;
cin >> x2 >> y2 >> z2;
airplanes.push_back({{x1, y1, z1}, {x2, y2, z2}});
}
double lo = 0, hi = 90;
if(!test_angle(hi - 1e-7)){
cout << "impossible\n";
return 0;
}
for(int i = 0; i < 100; i++) {
double mid = (lo + hi) / 2;
bool ok = test_angle(mid);
if(ok) hi = mid;
else lo = mid;
}
cout << fixed << setprecision(10) << lo << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4412kb
input:
1 1 3 -5 0 5 0 0 5 -10 10 10 10 10 10
output:
45.0000000000
result:
ok
Test #2:
score: 0
Accepted
time: 1ms
memory: 4272kb
input:
1 1 3 -5 0 5 0 0 5 -10 0 10 10 0 10
output:
26.5650511771
result:
ok
Test #3:
score: 0
Accepted
time: 1ms
memory: 4436kb
input:
1 1 3 -5 0 5 0 0 5 0 10 10 10 0 10
output:
46.6861433417
result:
ok
Test #4:
score: 0
Accepted
time: 1ms
memory: 4412kb
input:
1 1 3 -5 0 5 0 0 5 0 10 5 10 0 10
output:
59.4910411338
result:
ok
Test #5:
score: 0
Accepted
time: 1ms
memory: 4400kb
input:
1 1 3 -5 0 5 0 0 5 0 10 20 -10 0 10
output:
31.2196984474
result:
ok
Test #6:
score: 0
Accepted
time: 1ms
memory: 4400kb
input:
1 3 3 -5 0 5 0 0 5 -10 0 25 10 0 20 -5 10 10 10 -5 20 -4 1 100 5 10 100
output:
12.5288077092
result:
ok
Test #7:
score: 0
Accepted
time: 1ms
memory: 4244kb
input:
1 2 4 0 0 20 0 20 40 0 40 -10 30 30 30 30 30 -10 10 30 30 10 30
output:
45.0000000000
result:
ok
Test #8:
score: 0
Accepted
time: 1ms
memory: 4212kb
input:
1 4 4 0 0 20 0 20 40 0 40 -10 30 30 30 30 30 -10 20 30 30 20 30 -10 10 30 30 10 30 10 -10 30 10 50 30
output:
18.4349488229
result:
ok
Test #9:
score: 0
Accepted
time: 1ms
memory: 3920kb
input:
1 2 4 0 0 40 0 40 40 0 40 10 10 10 20 20 20 30 10 10 10 30 20
output:
impossible
result:
ok
Test #10:
score: 0
Accepted
time: 1ms
memory: 4020kb
input:
1 3 4 0 0 20 0 20 40 0 40 -10 30 30 15 30 30 5 30 30 30 30 30 1 50 30 21 50 30
output:
impossible
result:
ok
Test #11:
score: 0
Accepted
time: 1ms
memory: 4404kb
input:
1 1 4 0 0 40 0 40 40 0 40 -100 -100 20 100 100 10
output:
63.6657521531
result:
ok
Test #12:
score: 0
Accepted
time: 1ms
memory: 4408kb
input:
1 4 4 -10 -10 10 -10 10 10 -10 10 -100 0 10 100 0 10 0 100 10 0 -100 10 50 50 15 -50 -50 15 -50 50 15 50 -50 15
output:
43.3138566583
result:
ok
Test #13:
score: 0
Accepted
time: 12ms
memory: 4496kb
input:
1 100 100 822286 0 856789 53904 986567 124632 629039 119995 732157 187986 691605 224716 728650 288493 591087 278144 801573 440668 425257 269876 614456 446428 424157 350893 645680 606334 406524 432904 545628 659551 359831 495265 367048 578376 251435 457360 319990 680014 336526 849968 214009 658652 23...
output:
53.7906384311
result:
ok
Test #14:
score: 0
Accepted
time: 2ms
memory: 4164kb
input:
100 1 100 461002 481444 460618 481480 460584 481512 460833 481595 460670 481605 460545 481607 460942 481801 460526 481672 460912 481923 460765 481903 460505 481781 460430 481766 460589 481959 460593 482032 460477 481972 460440 481994 460510 482183 460285 481888 460387 482179 460246 481963 460303 482...
output:
impossible
result:
ok
Test #15:
score: 0
Accepted
time: 17ms
memory: 4648kb
input:
100 1 100 461002 481444 460618 481480 460584 481512 460833 481595 460670 481605 460545 481607 460942 481801 460526 481672 460912 481923 460765 481903 460505 481781 460430 481766 460589 481959 460593 482032 460477 481972 460440 481994 460510 482183 460285 481888 460387 482179 460246 481963 460303 482...
output:
33.6907956097
result:
ok
Test #16:
score: 0
Accepted
time: 18ms
memory: 4556kb
input:
100 1 100 461002 481444 460618 481480 460584 481512 460833 481595 460670 481605 460545 481607 460942 481801 460526 481672 460912 481923 460765 481903 460505 481781 460430 481766 460589 481959 460593 482032 460477 481972 460440 481994 460510 482183 460285 481888 460387 482179 460246 481963 460303 482...
output:
66.4027966421
result:
ok
Test #17:
score: 0
Accepted
time: 445ms
memory: 4704kb
input:
100 100 100 461002 481444 460618 481480 460584 481512 460833 481595 460670 481605 460545 481607 460942 481801 460526 481672 460912 481923 460765 481903 460505 481781 460430 481766 460589 481959 460593 482032 460477 481972 460440 481994 460510 482183 460285 481888 460387 482179 460246 481963 460303 4...
output:
4.1890016471
result:
ok
Test #18:
score: 0
Accepted
time: 45ms
memory: 4532kb
input:
100 11 100 461002 481444 460618 481480 460584 481512 460833 481595 460670 481605 460545 481607 460942 481801 460526 481672 460912 481923 460765 481903 460505 481781 460430 481766 460589 481959 460593 482032 460477 481972 460440 481994 460510 482183 460285 481888 460387 482179 460246 481963 460303 48...
output:
32.4119284772
result:
ok
Test #19:
score: 0
Accepted
time: 368ms
memory: 4632kb
input:
100 90 100 461002 481444 460618 481480 460584 481512 460833 481595 460670 481605 460545 481607 460942 481801 460526 481672 460912 481923 460765 481903 460505 481781 460430 481766 460589 481959 460593 482032 460477 481972 460440 481994 460510 482183 460285 481888 460387 482179 460246 481963 460303 48...
output:
5.5754489360
result:
ok
Extra Test:
score: 0
Extra Test Passed