QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#755717 | #6599. The Grand Tournament | SGColin | WA | 0ms | 3876kb | C++14 | 5.2kb | 2024-11-16 17:56:24 | 2024-11-16 17:56:25 |
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;
}
inline void work() {
int 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 (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);
return;
} else {
if (((A - C) | (A - D)) < 0) swap(A, B);
if (((D - A) | (D - B)) < 0) swap(C, D);
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, 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
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3704kb
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: -100
Wrong Answer
time: 0ms
memory: 3876kb
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 3.7500000000 3.7500000000 0.0000000000 3.7500000000 0.0000000000 3.7500000000 2.0000000000 4.0000000000
result:
wrong answer 3rd numbers differ - expected: '0.0000000', found: '3.7500000', error = '3.7500000'