QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#674553#5426. Drain the Water TankheyuhaoWA 0ms3652kbC++201.4kb2024-10-25 16:28:002024-10-25 16:28:00

Judging History

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

  • [2024-10-25 16:28:00]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3652kb
  • [2024-10-25 16:28:00]
  • 提交

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&&y1>y2)
            pos[i]=-1;
        else if(x1==x2&&y1<y2)
            pos[i]=1;
        else if(y1==y2)
            pos[i]=0;
        else
        {
            if((y1-y2)*(x1-x2)>0)
                pos[i]=1;
            else
                pos[i]=-1;
        }
    }
    int ans=0;
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        if(cnt==0)
            cnt=pos[i];
        else if(cnt!=pos[i]&&pos[i]!=0&&cnt<0)
        {
            ans++;
            cnt=0;
        }
        else if(pos[i]!=0)
        cnt=pos[i];
    }
    if(cnt<0)
    {
        int i=0;
        while(pos[i]==0)
            i++;
        if(pos[i]>0)
            ans++;
    }
    // for(int i=0;i<n;i++)
    //     cout<<pos[i]<<"\n";
    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;
 }

详细

Test #1:

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

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

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

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

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'