QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#632818#5426. Drain the Water TankCSQ#WA 1ms3604kbC++17979b2024-10-12 14:00:192024-10-12 14:00:19

Judging History

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

  • [2024-10-12 14:00:19]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3604kb
  • [2024-10-12 14:00:19]
  • 提交

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 dot(pii a,pii b){
	return a.fi*b.fi + a.se * b.se;
}
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){
			//cout<<i<<'\n';
			if(dot({a[i].fi-b.fi,a[i].se-b.se},{c.fi-b.fi,c.se-b.se}) >= 0)ans++;
		}
		if(b.se > a[i].se && c.se == a[i].se){
			if(dot({a[i].fi-b.fi,a[i].se-b.se},{c.fi-b.fi,c.se-b.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: 3604kb

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: 1ms
memory: 3540kb

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: 1ms
memory: 3508kb

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

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'