QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#755744#6599. The Grand TournamentSGColinWA 58ms4044kbC++145.3kb2024-11-16 17:58:412024-11-16 17:58:42

Judging History

你现在查看的是最新测评结果

  • [2024-11-16 17:58:42]
  • 评测
  • 测评结果:WA
  • 用时:58ms
  • 内存:4044kb
  • [2024-11-16 17:58:41]
  • 提交

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() {
    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 (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);
            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: 3880kb

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: 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
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: 58ms
memory: 4044kb

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:

0.0000000000
42.0000000000
12.0000000000
24.0000000000
25.0000000000
28.0000000000
99.0000000000
0.0000000000
135.0000000000
6.0000000000
42.0000000000
45.0000000000
120.0000000000
8.0000000000
84.0000000000
15.0000000000
16.0000000000
54.0000000000
36.0000000000
4.0000000000
0.5000000000
20.0000000...

result:

wrong answer 18th numbers differ - expected: '0.0000000', found: '54.0000000', error = '54.0000000'