QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#603236#7906. Almost Convexucup-team2112#WA 5ms3784kbC++202.7kb2024-10-01 15:26:272024-10-01 15:26:28

Judging History

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

  • [2024-10-01 15:26:28]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:3784kb
  • [2024-10-01 15:26:27]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

typedef struct P {
    i64 x, y;

    P(i64 x = 0, i64 y = 0) : x(x), y(y) {}
    P operator+(P r) { return P(x + r.x, y + r.y); }
    P operator-(P r) { return P(x - r.x, y - r.y); }
    P operator*(i64 r) { return P(x * r, y * r); }
    P operator/(i64 r) { return P(x / r, y / r); }
    bool operator<(const P &r) const { return x < r.x || (x == r.x && y < r.y); }
    bool operator==(const P &r) const { return x - r.x == 0 && y - r.y == 0; }
    bool upper() { return y > 0 || (y == 0 && x > 0); }
    void read() { scanf("%lf %lf", &x, &y); }
    void print() { printf("%.2f %.2f\n", x, y); }
}V;

i64 Cross(V A, V B) { return A.x*B.y - A.y*B.x; }

auto ConvexHull(std::vector<P> p) {
    sort(p.begin(), p.end());
    //p.erase(unique(p.begin(), p.end()), p.end());
    std::vector<P> ch;
    std::vector<int> id;
    int n = p.size();
    int m = 0;
    for(int i = 0; i < n; i++) {
        while(m > 1 && Cross(ch[m-1] - ch[m-2], p[i] - ch[m-2]) <= 0) ch.pop_back(), id.pop_back(), m--;
        ch.emplace_back(p[i]);
        id.emplace_back(i);
        m += 1;
    }
    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) ch.pop_back(), id.pop_back(), m--;
        ch.emplace_back(p[i]);
        id.emplace_back(i);
        m += 1;
    }
    if(n > 1) m--, ch.pop_back(), id.pop_back();
    return ch;
}

void solve() {
    int n;
    std::cin >> n;
    std::vector<P> p(n);
    for (int i = 0; i < n; i += 1) {
        std::cin >> p[i].x >> p[i].y;
    }
    auto ch = ConvexHull(p);
    
    int res = 1;
    std::vector<P> lst;
    for (int j = 0; j < n; j += 1) {
        bool nice = true;
        for (int i = 0; i < ch.size(); i += 1) {
            if (ch[i] == p[j]) {
                nice = false;
                break;
            }
        }
        if (nice) {
            lst.emplace_back(p[j]);
        }
    }
    for (int i = 0; i < ch.size(); i += 1) {
        auto p1 = ch[i];
        auto p2 = ch[(i + 1) % ch.size()];
        std::sort(lst.begin(), lst.end(), [&](P x, P y) {
            return Cross(x - p1, y - p1) < 0;
        });
        std::vector<P> cur;
        for (auto x : lst) {
            if (not cur.empty() && Cross(cur.back() - p2, x - p2) > 0) {
                cur.pop_back();
            }
            cur.emplace_back(x);
        }
        res += cur.size();
    }
    std::cout << res << "\n";
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    int T = 1;
    // std::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: 3784kb

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: 3568kb

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: 3512kb

input:

3
0 0
3 0
0 3

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

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: 3560kb

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: 5ms
memory: 3744kb

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:

43932

result:

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