QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#632985#5426. Drain the Water TankCSQ#WA 2ms3592kbC++17991b2024-10-12 14:19:082024-10-12 14:19:09

Judging History

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

  • [2024-10-12 14:19:09]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3592kb
  • [2024-10-12 14:19:08]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define rep(i,a,b) for(int i=a;i < b;i++)
#define all(x) begin(x),end(x)
#define sz(x) (int)(x.size())
typedef long long int ll;
typedef pair<ll,ll> pii;
typedef vector<int> vi;
#define fi first
#define se second
ll cross(pii a,pii b){
	return a.fi * b.se - a.se*b.fi;
}
int main()
{
	int n;
	cin>>n;
	vector<pii>a(n);
	int ans = 0;
	for(int i=0;i<n;i++)cin>>a[i].fi>>a[i].se;
	for(int i=0;i<n;i++){
		pii b = a[(i+n-1)%n];
		pii c = a[(i+1)%n];
		if(b.se > a[i].se && c.se >= a[i].se){ //if valley you must taleke
			//cout<<i<<'\n';
			if(cross({c.fi - a[i].fi,c.se - a[i].se},{b.fi - a[i].fi,b.se - a[i].se}) >= 0)ans++;
		}
		
		else if(b.se > a[i].se && c.se == a[i].se){
			if(cross({c.fi - a[i].fi,c.se - a[i].se},{b.fi - a[i].fi,b.se - a[i].se}) >= 0){
				int j = (i+1)%n;
				while(a[j].se == a[i].se){
					j++;
					j%=n;
				}
				if(a[j].se > a[i].se)ans++;
			}
		}
	}
	cout<<ans<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3536kb

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

input:

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

output:

2

result:

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