QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#686765#5426. Drain the Water Tankwangxiaorui#WA 0ms3704kbC++141.9kb2024-10-29 15:35:252024-10-29 15:35:26

Judging History

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

  • [2024-10-29 15:35:26]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3704kb
  • [2024-10-29 15:35:25]
  • 提交

answer

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

struct node{
	int x,y;
}a[2005];
int n,ans,f[2005];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>n;
//	if(n==3)
//	{
//		puts("1");
//		return 0;
//	}
	for(int i=0;i<n;i++) cin>>a[i].x>>a[i].y;
	for(int i=0;i<n;i++)
	{
		int dy1=(a[(i-1+n)%n].y-a[i].y),dx1=(a[(i-1+n)%n].x-a[i].x);
		int dy2=(a[(i+1)%n].x-a[i].x),dx2=(a[(i+1)%n].y-a[i].y);
		if(a[(i-1+n)%n].y>a[i].y&&a[i].y<a[(i+1)%n].y&&
		  (a[(i-1+n)%n].x<=a[i].x&&a[i].x<=a[(i+1)%n].x||
		   a[i].x>=a[(i-1+n)%n].x&&a[i].x>=a[(i+1)%n].x&&(dy1*dx2<dx1*dy2||!dx2)||
		   a[i].x<=a[(i-1+n)%n].x&&a[i].x<=a[(i+1)%n].x&&(dy1*dx2>dx1*dy2||!dx1))) ans++;
//		cerr<<i<<' '<<ans<<endl;
	}
//	cerr<<ans<<endl;
	for(int i=0;i<n;i++)
	{
		if(f[i]) continue;
		int l=i;
		while(a[l].y==a[i].y) l=(l-1+n)%n;
		int r=i;
		while(a[r].y==a[i].y) r=(r+1)%n;
//		cerr<<l<<' '<<r<<' '<<ans<<endl;
		if(l==(i-1+n)%n&&r==(i+1)%n) continue;
		if(a[l].y>a[i].y&&a[i].y<a[r].y&&a[(l+1)%n].x<=a[(r-1+n)%n].x)
		{
			if(l==r)
			{
				for(int j=0;j<n;j++) f[j]=1;
				ans++;
				continue;
			}
			for(int j=l;j!=r;j=(j+1)%n)
			{
				f[j]=1;
			}
			ans++;
		}
	}
//	int p=0;
//	for(int i=1;i<n;i++)
//	{
//		if(a[i].y<a[p].y) p=i;
//	}
//	p=(p-1+n)%n;
//	int fl=1;
//	for(int i=p;i<n;i++)
//	{
//		if(a[i].x<a[(i-1+n)%n].x) fl=0;
//		if(a[i].x>a[(i-1+n)%n].x) fl=1;
//		if(fl&&a[(i-2+n)%n].y>=a[(i-1+n)%n].y&&a[(i-1+n)%n].y<a[i].y) ans++;
////		cerr<<i<<' '<<fl<<' '<<ans<<endl;
//	}
//	for(int i=0;i<p;i++)
//	{
//		if(a[i].x<a[(i-1+n)%n].x) fl=0;
//		if(a[i].x>a[(i-1+n)%n].x) fl=1;
//		if(fl&&a[(i-2+n)%n].y>=a[(i-1+n)%n].y&&a[(i-1+n)%n].y<a[i].y) ans++;
//	}
	cout<<ans;
	return 0;
}
/*
15
1 4
2 1
3 0
4 2
5 1
7 8
8 0
10 5
8 10
6 8
5 10
1 10
4 8
4 4
2 7

16
1 5
2 2
3 2
3 1
5 0
7 0
7 2
9 2
9 4
8 4
8 3
5 3
5 6
4 4
3 6
3 3
*/ 

詳細信息

Test #1:

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

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

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

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

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'