QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#668661#5426. Drain the Water Tanklmx111WA 0ms3704kbC++201.9kb2024-10-23 15:24:232024-10-23 15:24:26

Judging History

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

  • [2024-10-23 15:24:26]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3704kb
  • [2024-10-23 15:24:23]
  • 提交

answer

// Coded by hjxddl
#include <bits/stdc++.h>
#define ll long long
#define db double
const int N = 2e5 + 5;
int n;
int ck(int k, std::pair<ll, ll> (&a)[]) {
    int cnt = 0;
    auto [x, y] = a[k];
    for (int i = 1; i <= n; i++) {
        auto [x1, y1] = a[i];
        auto [x2, y2] = a[i + 1];
        if (i != k && x1 == x && y1 < y) {
            auto [x3, y3] = a[i - 1];
            if (x1 == x2 || (std::min(x1, x2) == std::min(x1, x3) && std::min(x1, x2) == x1) || (std::max(x1, x2) == std::max(x1, x3) && std::max(x1, x2) == x1))
                ;
            else
                cnt++;
        }
        if (x1 < x && x < x2) {
            if (y1 == y2 && y1 < y) {
                cnt++;
                continue;
            }
            if (x1 - x2 > 0) {
                if ((y - y2) * (x1 - x2) > (x - x2) * (y1 - y2))
                    cnt++;
            } else {
                if ((y - y2) * (x1 - x2) < (x - x2) * (y1 - y2))
                    cnt++;
            }
        }
    }
    // std::cerr << cnt << '\n';
    return cnt & 1 ^ 1;
}
void solve() {
    std::cin >> n;
    std::pair<ll, ll> a[n + 5];
    for (int i = 1; i <= n; i++) {
        std::cin >> a[i].first >> a[i].second;
    }
    a[n + 1] = a[1];
    a[0] = a[n];
    int ans = 0;
    bool vis = 0;
    for (int i = 0; i <= n; i++) {
        if (a[i + 1].second > a[i].second) {
            if (vis) {
                // std::cerr << i << " " << a[i].first << " " << a[i].second << " \n";
                ans += ck(i, a);
            }
            vis = 0;
        }
        if (a[i + 1].second < a[i].second)
            vis = 1;
    }
    std::cout << ans << '\n';
}
int main() {
    std::ios::sync_with_stdio(0);
    std::cin.tie(0), std::cout.tie(0);
    int t = 1;
    // std::cin >> t;
    while (t--) {
        solve();
    }
    std::cout << std::flush;
}

详细

Test #1:

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

input:

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

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

8
4 4
0 4
0 2
1 2
2 2
2 0
3 0
4 0

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

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

output:

2

result:

ok 1 number(s): "2"

Test #4:

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

input:

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

output:

2

result:

ok 1 number(s): "2"

Test #5:

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

input:

8
0 0
1 0
3 -1
3 0
1 1
4 1
5 0
3 4

output:

2

result:

ok 1 number(s): "2"

Test #6:

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

input:

5
0 0
170 0
140 30
60 30
0 70

output:

1

result:

ok 1 number(s): "1"

Test #7:

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

input:

5
0 0
170 0
140 30
60 30
0 100

output:

1

result:

ok 1 number(s): "1"

Test #8:

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

input:

5
0 0
1 2
1 5
0 2
0 1

output:

1

result:

ok 1 number(s): "1"

Test #9:

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

input:

3
0 0
100 0
0 100

output:

1

result:

ok 1 number(s): "1"

Test #10:

score: -100
Wrong Answer
time: 0ms
memory: 3632kb

input:

3
200 0
100 100
0 0

output:

0

result:

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