QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#768306#9520. Concave HullDopplerXDWA 37ms10032kbC++203.6kb2024-11-21 08:55:032024-11-21 08:55:04

Judging History

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

  • [2024-11-21 08:55:04]
  • 评测
  • 测评结果:WA
  • 用时:37ms
  • 内存:10032kb
  • [2024-11-21 08:55:03]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 5;

const double pi = acos(-1.0);
const double eps = 1e-8;

// 判断 x 的大小,<0 返回 -1,>0 返回 1,==0 返回 0
int sgn(double x) {
    if (fabs(x) < eps) return 0;
    else return x < 0 ? -1 : 1;
}

struct Point {
    ll x, y;
    Point() {}
    Point(ll x, ll y) : x(x), y(y) {}

    Point operator + (const Point& B) const { return Point(x + B.x, y + B.y); }
    Point operator - (const Point& B) const { return Point(x - B.x, y - B.y); }
    // Point operator * (double k) const { return Point(x * k, y * k); }
    // Point operator / (double k) const { return Point(x / k, y / k); }

    bool operator == (const Point& B) const {
        return sgn(x - B.x) == 0 && sgn(y - B.y) == 0;
    }
    bool operator < (const Point& B) const {
        return sgn(x - B.x) < 0 || sgn(x - B.x) == 0 && sgn(y - B.y) < 0;
    }
};
typedef Point Vector;

class Geometry {
public:
    static double Distance(const Point& A, const Point& B) {
        return sqrt((A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y));
    }

    static ll Cross(const Vector& A, const Vector& B) {
        return A.x * B.y - A.y * B.x;
    }

    static ll Area2(const Point& A, const Point& B, const Point& C) {
        return Cross(B - A, C - A);
    }
};

class PolygonOps {
public:
    static ll Area(int n, Point* ch) {
        ll area = 0;
        for (int i = 0; i < n; i++)
            area += Geometry::Cross(ch[i], ch[(i + 1) % n]);
        return area;
    }
};

int Convex_hull(Point* p, int n, Point* ch) {
    sort(p, p + n);
    int v = 0;
    for (int i = 0; i < n; i++) {
        while (v > 1 && sgn(Geometry::Cross(ch[v - 1] - ch[v - 2], p[i] - ch[v - 1])) <= 0) {
            v--;
        }
        ch[v++] = p[i];
    }
    int j = v;
    for (int i = n - 1; i >= 0; i--) {
        while (v > j && sgn(Geometry::Cross(ch[v - 1] - ch[v - 2], p[i] - ch[v - 1])) <= 0) {
            v--;
        }
        ch[v++] = p[i];
    }
    if (n > 1) v--;
    return v;
}

int n, n_left;
Point p[N], Left[N];
Point ch[N], chL[N];

void solve() {
    cin >> n;
    n_left = 0;
    for (int i = 0; i < n; i++) {
        cin >> p[i].x >> p[i].y;
    }
    int v = Convex_hull(p, n, ch);
    set<Point> st;
    for (int i = 0; i < v; i++) {
        st.emplace(ch[i]);
    }
    for (int i = 0; i < n; i++) {
        if (!st.count(p[i])) {
            Left[n_left++] = p[i];
        }
    }
    int vL = Convex_hull(Left, n_left, chL);
    if (vL == 0) {
        cout << -1 << '\n';
        return;
    }
    // cerr << "v: " << v << '\n';
    // cerr << "vL: " << vL << ", n_left: " << n_left << '\n';
    ll area = PolygonOps::Area(v, ch);
    ll ans = 0;
    ch[v] = ch[0];
    chL[vL] = chL[0];
    for (int i = 0, j = 0; i < v; i++) {
        ll tri_0, tri_1;
        int cnt = 0;
        while (cnt < v &&
            (tri_0 = Geometry::Area2(chL[j], ch[i], ch[i + 1])) >=
            (tri_1 = Geometry::Area2(chL[j + 1], ch[i], ch[i + 1]))) {
            j = (j + 1) % vL;
            cnt++;
        }
        ans = std::max(ans, area - tri_0);
    }
    // for (int i = 0; i < v; i++) {
    //     for (int j = 0; j < vL; j++) {
    //         ll tri = Geometry::Area2(chL[j], ch[i], ch[i + 1]);
    //         ans = std::max(ans, area - tri);
    //     }
    // }
    cout << ans << '\n';
}
int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int _T = 1;
    cin >> _T;
    while (_T--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7968kb

input:

2
6
-2 0
1 -2
5 2
0 4
1 2
3 1
4
0 0
1 0
0 1
1 1

output:

40
-1

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 7672kb

input:

10
243
-494423502 -591557038
-493438474 -648991734
-493289308 -656152126
-491185085 -661710614
-489063449 -666925265
-464265894 -709944049
-447472922 -737242534
-415977509 -773788538
-394263365 -797285016
-382728841 -807396819
-373481975 -814685302
-368242265 -818267002
-344482838 -833805545
-279398...

output:

2178418010787347715
1826413114144932145
1651687576234220014
1883871859778998985
2119126281997959892
894016174881844630
2271191316922158910
1998643358049669416
1740474221286618711
1168195646932543192

result:

ok 10 lines

Test #3:

score: 0
Accepted
time: 25ms
memory: 10032kb

input:

1000
125
64661186 -13143076
302828013 -185438065
-418713797 -191594241
430218126 -397441626
354327250 -836704374
149668812 -598584998
311305970 66790541
199720625 -592356787
468137 -584752683
258775829 96211747
-358669612 -134890109
-129221188 -998432368
-277309896 -140056561
356901185 420557649
-51...

output:

1986320445246155278
1900093336073022078
1612088392301142476
2012259136539173407
1819942017252118749
1772230185841892196
1164835025329039520
1527446155241140517
1807368432185303666
1236918659444944569
1306839249967484778
1984123720246784099
1868728080720036006
667458140583450322
2127932992585026491
4...

result:

ok 1000 lines

Test #4:

score: -100
Wrong Answer
time: 37ms
memory: 7968kb

input:

10000
9
484630042 51929469
-40468396 -517784096
98214104 -103353239
629244333 -475172587
106398764 153884485
49211709 -44865749
1 10
166321833 -247717657
406208245 668933360
13
548702216 -631976459
37150086 -292461024
707804811 -486185860
239775286 -903166050
10096571 -541890068
686103484 558731937
...

output:

950319193795831919
1661025342421008544
1285164852091455548
1159924751776806668
1206071151805176722
794021230296144371
699991678992587791
1133990718508584290
1486311831172661605
984875884297072200
1327767982175057345
758247019006396699
1355381234262206155
1139262078529131471
1613462877860621700
12392...

result:

wrong answer 9084th lines differ - expected: '611380764223647425', found: '564941195100460775'