曲线谜题:栈

样例输入 1

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

样例输出 1

YES

样例输入 2

2 2 4
0 0 2 2
2 0 0 1
0 2 1 2
1 1 2 1

样例输出 2

NO

样例输入 3

5 5 7
0 0 2 4
2 3 4 5
3 5 5 2
5 5 5 4
0 3 5 1
2 2 4 4
0 5 4 1

样例输出 3

YES

样例输入 4

1 1 2
0 0 1 1
1 0 0 1

 

#include <bits/stdc++.h>
using namespace std;
int r,c,n,cnt;
struct node
{
	 int x,y,id,opt;
} a[200001];
bool operator < (node x,node y)
{
	  if (x.opt==y.opt)
	  {
	  	  if (x.opt==1)
	  	  return x.y<y.y;
	  	  if (x.opt==2)
	  	  return x.x<y.x;
	  	  if (x.opt==3)
	  	  return x.y>y.y;
	  	  if (x.opt==4)
	  	  return x.x>y.x;
	  }
	  return x.opt<y.opt;
}
bool check (int x,int y)
{
	  return x==0||x==r||y==0||y==c;
}
int get (int x,int y)
{
	 if (x==0)
	 return 1;
	 if (y==c)
	 return 2;
	 if (x==r)
	 return 3;
	 if (y==0)
	 return 4;
}
stack<int>s;
int main()
{
	scanf("%d%d%d",&r,&c,&n);
	for(int i=1;i<=n;i++)
	{
		int x1,x2,y1,y2;
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		if (check(x1,y1)&&check(x2,y2))
		{
			a[++cnt].x=x1;
			a[cnt].y=y1;
			a[cnt].id=i;
			a[cnt].opt=get(x1,y1);
			a[++cnt].x=x2;
			a[cnt].y=y2;
			a[cnt].id=i;
			a[cnt].opt=get(x2,y2);
		}
	}
	sort(a+1,a+1+cnt);
	for (int i=1;i<=cnt;i++)
	{
		 if (!s.empty()&&a[i].id==s.top())
		 s.pop();
		 else
		 s.push(a[i].id);
	}
	if (s.empty())
	puts("YES");
	else
	puts("NO");
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值