HDU 5480 Conturbatio

Conturbatio

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 970    Accepted Submission(s): 438


Problem Description
There are many rook on a chessboard, a rook can attack the row and column it belongs, including its own place.

There are also many queries, each query gives a rectangle on the chess board, and asks whether every grid in the rectangle will be attacked by any rook?
 

Input
The first line of the input is a integer  T , meaning that there are  T  test cases.

Every test cases begin with four integers  n,m,K,Q .
K  is the number of Rook,  Q  is the number of queries.

Then  K  lines follow, each contain two integers  x,y  describing the coordinate of Rook.

Then  Q  lines follow, each contain four integers  x1,y1,x2,y2  describing the left-down and right-up coordinates of query.

1n,m,K,Q100,000 .

1xn,1ym .

1x1x2n,1y1y2m .
 

Output
For every query output "Yes" or "No" as mentioned above.
 

Sample Input
  
  
2 2 2 1 2 1 1 1 1 1 2 2 1 2 2 2 2 2 1 1 1 1 2 2 1 2 2
 

Sample Output
  
  
Yes No Yes
Hint
Huge input, scanf recommended.
 

Source
 

Recommend
hujie   |   We have carefully selected several similar problems for you:   5867  5866  5865  5864  5863 
<span style="font-family:SimSun;font-size:14px;background-color: rgb(255, 255, 255);">在一个<span class="katex" style="white-space: nowrap; line-height: 1.2;"></span></span><pre><span style="font-family:SimSun;font-size:14px;background-color: rgb(255, 255, 255);"><span class="katex" style="line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">n \times m</span></span><span class="katex" style="line-height: 1.2; white-space: nowrap;"><span class="katex-html" style="display: inline-block;"><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord mathit" style="font-style: italic;">n</span><span class="mbin" style="margin-left: 0.22222em;">×</span><span class="mord mathit" style="font-style: italic; margin-left: 0.22222em;">m</span></span></span></span>的国际象棋棋盘上有很多车(Rook),其中车可以攻击他所属的一行或一列,包括它自己所在的位置。
现在还有很多询问,每次询问给定一个棋盘内部的矩形,问矩形内部的所有格子是否都被车攻击到?<span class="katex" style="line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">Q</span></span><span class="katex" style="line-height: 1.2; white-space: nowrap;"><span class="katex-html" style="display: inline-block;"><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord mathit" style="font-style: italic;">k为车的数量Q</span></span></span></span>为询问的</span>
个数。接下来有KK行,每行两个整数x , yx,y , 表示车所在的坐标。再接下来有QQ行,每行4个整数x1 , y1 , x2 , y2x1,y1,x2,y2,表示询问的
矩形的左下角与右上角的坐标。

 
  思路:如果只要是行能被全部攻击,或者列被全部攻击,那么所有的格子就能被全部攻击。 
 
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[100010],b[100010];
int main()
{
	int n,m,k,q,i,j,t;
	scanf("%d",&t);
	while(t--)
	{
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		scanf("%d%d%d%d",&n,&m,&k,&q);
		for(i=0;i<k;i++)
		{
			int x,y;
			scanf("%d%d",&x,&y);
			a[x]=1;
			b[y]=1;
		}
		for(i=1;i<=n;i++)
		a[i]+=a[i-1];
		for(i=1;i<=m;i++)
		b[i]+=b[i-1];
		while(q--)
		{
			int x1,y1,x2,y2;
			scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
			if(x2-x1+1==a[x2]-a[x1-1]||y2-y1+1==b[y2]-b[y1-1]) 
			printf("Yes\n");
			else
			printf("No\n");
		}
	}
	return 0;
}




 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值