QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#533460#7906. Almost Convexabbcc_1WA 228ms3768kbC++202.8kb2024-08-25 23:35:002024-08-25 23:35:00

Judging History

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

  • [2024-08-25 23:35:00]
  • 评测
  • 测评结果:WA
  • 用时:228ms
  • 内存:3768kb
  • [2024-08-25 23:35:00]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

using f64 = i64;

struct Point {
    f64 x, y;
    Point(f64 x = 0, f64 y = 0) : x(x), y(y) {}
    Point& operator=(const Point& p) {
        x = p.x;
        y = p.y;
        return *this;
    }
};

typedef Point Vector;

Vector operator+(Vector A, Vector B) { return {A.x + B.x, A.y + B.y}; }

Vector operator-(Vector A, Vector B) { return {A.x - B.x, A.y - B.y}; }

Vector operator*(Vector A, f64 p) { return {A.x * p, A.y * p}; }

Vector operator/(Vector A, f64 p) { return {A.x / p, A.y / p}; }

bool operator<(const Point& a, const Point& b) { return a.x < b.x || (a.x == b.x && a.y < b.y); }

f64 Cross(Vector A, Vector B) { return A.x * B.y - A.y * B.x; }

f64 Dot(Vector A, Vector B) { return A.x * B.x + A.y * B.y; }

bool operator==(const Point& a, const Point& b) { return a.x == b.x && a.y == b.y; }

f64 Dist2(const Point& A, const Point& B) {
    return (A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y);
}

double Dist(const Point& A, const Point& B) { return sqrt(Dist2(A, B)); }

vector<int> ConvexHull(vector<Point>& p) {
    sort(p.begin(), p.end());
    p.erase(unique(p.begin(), p.end()), p.end());
    int n = p.size(), m = 0;
    vector<Point> ch(n + 1);
    vector<int> rt;
    for (int i = 0; i < n; i++) {
        while (m > 1 && Cross(ch[m - 1] - ch[m - 2], p[i] - ch[m - 2]) <= 0) m--;
        ch[m++] = p[i];
        rt.emplace_back(i);
    }
    int k = m;
    for (int i = n - 2; i >= 0; i--) {
        while (m > k && Cross(ch[m - 1] - ch[m - 2], p[i] - ch[m - 2]) <= 0) m--;
        ch[m++] = p[i];
        rt.emplace_back(i);
    }
    if (n > 1) m--;
    rt.resize(m);
    return rt;
}

struct Node {
    Point p;
    int id;
    Node(Point _p, int _id) : p(_p), id(_id) {}
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    vector<Point> p(n);
    for (int i = 0; i < n; i += 1) {
        cin >> p[i].x >> p[i].y;
    }
    vector<int> convex = ConvexHull(p);
    vector<bool> vis(n);
    for (int i = 0; i < convex.size(); i += 1) {
        vis[convex[i]] = true;
    }
    i64 ans = 1;
    for (int i = 0; i < n; i += 1) {
        if (vis[i]) continue;
        vector<Node> d;
        for (int j = 0; j < n; j += 1) {
            if (i == j) continue;
            d.emplace_back(p[j], vis[j]);
        }
        sort(d.begin(), d.end(), [&](Node& a, Node& b) {
            if (Cross(a.p - p[i], b.p - p[i]) > 0) return true;
            else return false;
        });
        int m = d.size();
        for (int j = 0; j < m; j += 1) {
            if (d[j].id && d[(j + 1) % m].id) {
                ans += 1;
                // cerr << p[i].x << " " << p
            }
        }
    }
    cout << ans << "\n";

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3600kb

input:

7
1 4
4 0
2 3
3 1
3 5
0 0
2 4

output:

9

result:

ok 1 number(s): "9"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

5
4 0
0 0
2 1
3 3
3 1

output:

5

result:

ok 1 number(s): "5"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

3
0 0
3 0
0 3

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3652kb

input:

6
0 0
3 0
3 2
0 2
1 1
2 1

output:

7

result:

ok 1 number(s): "7"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3640kb

input:

4
0 0
0 3
3 0
3 3

output:

1

result:

ok 1 number(s): "1"

Test #6:

score: -100
Wrong Answer
time: 228ms
memory: 3768kb

input:

2000
86166 617851
383354 -277127
844986 386868
-577988 453392
-341125 -386775
-543914 -210860
-429613 606701
-343534 893727
841399 339305
446761 -327040
-218558 -907983
787284 361823
950395 287044
-351577 -843823
-198755 138512
-306560 -483261
-487474 -857400
885637 -240518
-297576 603522
-748283 33...

output:

15548

result:

wrong answer 1st numbers differ - expected: '718', found: '15548'