QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#674475#5426. Drain the Water TankheyuhaoWA 0ms3644kbC++201.5kb2024-10-25 15:57:252024-10-25 15:57:27

Judging History

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

  • [2024-10-25 15:57:27]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3644kb
  • [2024-10-25 15:57:25]
  • 提交

answer

#include<bits/stdc++.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int n;
const int MAX=1e9;
void solve()
{
    cin>>n;
    pair<int,int> a[2010];
    for(int i=0;i<n;i++)
    cin>>a[i].first>>a[i].second;
    int pos[2010];
    for(int i=0;i<n;i++)
    {
        int x1=a[i].first,y1=a[i].second;
        int x2=a[(i+1)%n].first,y2=a[(i+1)%n].second;
        if(x1==x2)
            pos[i]=MAX;
        else if(y1==y2)
            pos[i]=-MAX;
        else
        {
            if((y1-y2)*(x1-x2)>0)
                pos[i]=1;
            else
                pos[i]=0;
        }
    }
    int ans=0;
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        if(pos[i]==0&&pos[(i+1)%n]==1)
        {
            ans++;
            cnt=0;
        }
        if(pos[i]==MAX&&pos[(i+1)%n]==1)
        {
            ans++;
            cnt=0;
        }
        if(pos[i]==0&&pos[(i+1)%n]==MAX)
        {
            ans++;
            cnt=0;
        }
        if(pos[i]==MAX)
        {
            if(cnt!=0)
                ans++,cnt=0;
            else
                cnt++;
        }
    }
    // for(int i=0;i<n;i++)
    // {
    //     cout<<pos[i]<<" ";
    // }
    // if(ans==0)
    //     ans=1;
    cout<<ans<<"\n";
}
int main()
 {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    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: 3632kb

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

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

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

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'