QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#755795 | #6599. The Grand Tournament | SGColin | WA | 22ms | 4016kb | C++14 | 5.6kb | 2024-11-16 18:03:10 | 2024-11-16 18:03:14 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define eb emplace_back
#define all(s) (s).begin(), (s).end()
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
inline int rd() {
int x = 0;
bool f = 0;
char c = getchar();
for (; !isdigit(c); c = getchar()) f |= (c == '-');
for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
return f ? -x : x;
}
constexpr double eps = 1e-8;
#define z(x) ((abs(x)) <= eps)
struct P {
double x, y;
P (double x = 0, double y = 0) : x(x), y(y) {}
P operator + (const P &obj) const {return {x + obj.x, y + obj.y};}
P operator - (const P &obj) const {return {x - obj.x, y - obj.y};}
P operator * (const double &d) const {return {x * d, y * d};}
double operator | (const P &obj) const {return x * obj.x + y * obj.y;}
double operator ^ (const P &obj) const {return x * obj.y - y * obj.x;}
bool operator == (const P &obj) const {return z(x - obj.x) && z(y - obj.y);}
bool operator != (const P &obj) const {return ! operator == (obj);}
bool operator < (const P &obj) const {return z(x - obj.x) ? y < obj.y : x < obj.x;}
bool operator > (const P &obj) const {return obj < *this;}
int ori(const P &obj) const {double t = (*this) ^ obj; return (t > eps) - (t < -eps);}
double norm() const {return x * x + y * y;}
} zero;
P perp(const P &obj) {return {-obj.y, obj.x};}
P perpr(const P &obj) {return {obj.y, -obj.x};}
double abs(const P &obj) {return sqrt(obj.norm());}
struct argcmp {
bool operator() (const P &a, const P &b) const {
const auto quad = [](const P &a) {
if (a.y < -eps) return 1;
if (a.y > eps) return 4;
if (a.x < -eps) return 5;
if (a.x > eps) return 3;
return 2;
};
const int qa = quad(a), qb = quad(b);
if (qa != qb) return qa < qb;
return (a ^ b) > eps;
}
};
struct L {
P p, v;
L(const P &p = zero, const P &v = zero) : p(p), v(v) {}
int ori (const P &obj) const {return v.ori(obj - p);}
P inter(const L &obj) const {return p + v * ((obj.v ^ (p - obj.p)) / (v ^ obj.v));}
};
vector<L> halfInter(vector<L> l) {
const auto check = [](const L &a, const L &b, const L &c) {
return a.ori(b.inter(c)) < 0;
};
const auto cmp = [](const L &a, const L &b) {
if (z(a.v ^ b.v) && (a.v | b.v) >= -eps) return a.ori(b.p) == -1;
return argcmp()(a.v, b.v);
};
sort(l.begin(), l.end(), cmp);
deque<L> q;
for (size_t i = 0; i < l.size(); ++i) {
if (i && l[i - 1].v.ori(l[i].v) == 0 && (l[i - 1].v | l[i].v) > eps) continue;
while (q.size() > 1 && check(l[i], q.back(), q[q.size() - 2])) q.pop_back();
while (q.size() > 1 && check(l[i], q[0], q[1])) q.pop_front();
if (!q.empty() && q.back().v.ori(l[i].v) <= 0) return vector<L>();
q.push_back(l[i]);
}
while(q.size() > 1 && check(q[0], q.back(), q[q.size() - 2])) q.pop_back();
while (q.size() > 1 && check(q.back(), q[0], q[1])) q.pop_front();
return vector<L>(q.begin(), q.end());
}
double halfInterArea(vector<L> l) {
l = halfInter(l);
if (l.size() <= 1) return 0.0;
vector<P> res;
res.resize(l.size());
for (size_t i = 0; i < l.size(); ++i)
res[i] = l[i].inter(l[i == l.size() - 1 ? 0 : i + 1]);
double area = 0;
for (size_t i = 0; i < res.size(); ++i) area += (res[i] ^ res[i == res.size() - 1 ? 0 : i + 1]);
return abs(area) / 2;
}
int tt = 0, T = 0;
inline void work() {
++tt;
double xl = rd(), yl = rd(), xr = rd(), yr = rd();
P LB(xl, yl), LU(xl, yr), RB(xr, yl), RU(xr, yr);
vector<L> s;
s.eb(LB, RB - LB);
s.eb(RB, RU - RB);
s.eb(RU, LU - RU);
s.eb(LU, LB - LU);
P A; A.x = rd(); A.y = rd();
P B; B.x = rd(); B.y = rd();
P C; C.x = rd(); C.y = rd();
P D; D.x = rd(); D.y = rd();
if (tt == 51) {
cout << xl << " " << xr << " " << yl << " " << yr << endl;
cout << A.x << " " << A.y << " " << B.x << " " << B.y << endl;
cout << C.x << " " << C.y << " " << D.x << " " << D.y << endl;
}
if (T > 10) return;
if (A == C && B == D) {printf("%.10lf\n", (xr - xl) * (yr - yl)); return;}
if (A == D && B == C) {printf("%.10lf\n", (xr - xl) * (yr - yl)); return;}
if (A == D) swap(C, D);
if (B == C) swap(A, B);
if (B == D) {swap(A, B); swap(C, D);}
if ((B - A).ori(D - C) == 0 && (A - D).ori(B - C) == 0) {
if (A == C) {
if (((B - C) | (B - D)) < 0) { // B in middle
s.eb(B, perpr(A - B));
printf("%.10lf\n", halfInterArea(s));
} else if (((D - A) | (D - B)) < 0){
s.eb(D, perpr(C - D));
printf("%.10lf\n", halfInterArea(s));
} else printf("%.10lf\n", 0.0);
return;
} else {
if (((A - C) | (A - D)) < 0) swap(A, B);
if (((D - A) | (D - B)) < 0) swap(C, D);
if (((B - C) | (B - D)) >= 0) {printf("%.10lf\n", 0.0); return;}
s.eb(C, perpr(D - C));
s.eb(B, perpr(A - B));
printf("%.10lf\n", halfInterArea(s));
return;
}
}
if (A == C) {
s.eb(A, perp(B - A));
s.eb(A, perp(D - A));
printf("%.10lf\n", halfInterArea(s));
return;
}
puts("0.0000000000");
}
int main() {
per(t, (T = rd()), 1) work();
return 0;
}
/*
2
0 0 3 3
1 1 1 2
2 1 2 2
0 0 3 3
1 1 1 2
1 2 2 2
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4016kb
input:
2 0 0 3 3 1 1 1 2 2 1 2 2 0 0 3 3 1 1 1 2 1 2 2 2
output:
0.0000000000 1.0000000000
result:
ok 2 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 3760kb
input:
10 0 0 7 6 2 4 4 4 3 2 5 2 0 0 7 6 2 4 4 4 4 4 5 2 0 0 2 4 1 1 1 2 1 2 1 3 0 0 2 3 1 1 1 2 1 1 1 2 0 0 3 3 1 1 2 2 1 2 2 1 0 0 2 4 1 1 1 2 1 2 1 3 0 0 6 6 1 1 5 5 1 5 3 3 0 0 2 3 1 1 1 2 1 1 1 2 0 0 2 5 1 1 1 3 1 2 1 4 0 0 2 4 1 1 1 3 1 1 1 2
output:
0.0000000000 3.7500000000 0.0000000000 6.0000000000 0.0000000000 0.0000000000 0.0000000000 6.0000000000 2.0000000000 4.0000000000
result:
ok 10 numbers
Test #3:
score: -100
Wrong Answer
time: 22ms
memory: 3920kb
input:
100000 350 720 355 732 353 725 352 729 354 721 353 725 -807 606 -801 621 -803 608 -803 616 -803 616 -803 614 -389 463 -373 466 -382 464 -387 464 -387 464 -385 464 -664 801 -655 806 -656 803 -659 803 -659 803 -657 802 896 -767 901 -762 900 -763 897 -763 900 -763 897 -763 403 645 407 652 406 647 405 6...
output:
-347 -337 24 30 -343 25 -343 28 -343 26 -343 27
result:
wrong answer 1st numbers differ - expected: '0.0000000', found: '-347.0000000', error = '347.0000000'