QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#674489#5426. Drain the Water Tankyumingsk#WA 0ms3608kbC++201.9kb2024-10-25 16:02:402024-10-25 16:02:41

Judging History

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

  • [2024-10-25 16:02:41]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3608kb
  • [2024-10-25 16:02:40]
  • 提交

answer

#pragma GCC optimize(3, "Ofast", "inline")
#include <iostream>
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define INF 0x3f3f3f3f
#define L_INF 0x7f3f3f3f3f3f3f3f
#define db cout << "debug\n";

using namespace std;
const int Mod = 998244353;
using ll = long long;
int cross(pair<int, int> s1, pair<int, int> s2)
{
    return s1.first * s2.first + s2.second * s2.second;
}
void solve()
{
    int n;
    cin >> n;
    vector<pair<int, int>> p(2 * n + 3);
    for (int i = 1; i <= n; i++)
    {
        int x, y;
        cin >> x >> y;
        p[i] = {x, y};
        p[i + n] = {x, y};
    }

    // vector<int> vis(2n , 0);
    vector<pair<int, int>> kt(2 * n + 1);
    for (int i = 1; i <= 2 * n - 1; i++)
    {
        kt[i] = {p[i + 1].first - p[i].first, p[i + 1].second - p[i].second};
    }
    // {-y,x}
    int ans = 0;
    int pos = 1;

    for (int i = 2; i <= n; i++)
    {
        if (p[i].second > p[pos].second)
        {
            pos = i;
        }
        else if (p[i].second == p[pos].second)
        {
            if (p[i].first > p[pos].first)
                pos = i;
        }
    }
    pair<int, int> lst = p[pos];
    for (int i = pos + 1; i <= pos + n - 1; i++)
    {
        if (lst.second < 0 && kt[i].second > 0) // 向下  (x,y)
        {
            pair<int, int> tmp = {-kt[i - 1].second, kt[i - 1].first};
            if (cross(tmp, kt[i]) > 0)
                ans++;
        }
        if (kt[i].second != 0)
            lst = kt[i];
    }
    cout << ans << '\n';
}
int main()
{
    IOS;
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#ifndef ONLINE_JUDGE
    clock_t start_time = clock();
#endif
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
#ifndef ONLINE_JUDGE
    // cout << "Used " << (double)(clock() - start_time) << " ms" << endl;
#endif
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

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

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

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

input:

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

output:

1

result:

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