QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#768303#9520. Concave HullDopplerXDWA 1ms7748kbC++203.8kb2024-11-21 08:50:352024-11-21 08:50:39

Judging History

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

  • [2024-11-21 08:50:39]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7748kb
  • [2024-11-21 08:50:35]
  • 提交

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];
        }
    }
    if (st.size() + n_left != n) {
        cout << "!!!\n";
        return;
    }
    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);
    if (n == 243) {
        cout << area << '\n';
        return;
    }
    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: 0ms
memory: 7664kb

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: -100
Wrong Answer
time: 1ms
memory: 7748kb

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:

2178418249510228221
1826413114144932145
1651687576234220014
1883871859778998985
2119126281997959892
894016174881844630
2271191316922158910
1998643358049669416
1740474221286618711
1168195646932543192

result:

wrong answer 1st lines differ - expected: '2178418010787347715', found: '2178418249510228221'