【杭电5480】Conturbatio象棋--车

 Conturbatio
Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

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  , meaning that there are   test cases. 

Every test cases begin with four integers 
 is the number of Rook,   is the number of queries. 

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

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






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
题意:有一个n*m的棋盘 K个车,车可以攻击它所在的一列或一行,包括自己所在位置,有Q个查询,
      输入K行(x,y)表示车的坐标,然后输入Q行,每行4个数x1 y1 x2 y2分别表示矩形的左下角坐标和右上角坐                 标,判断矩形内的人能否被全部攻击,是的话输出yes,不是输出no
题解:标记车的行列坐标,表示可以攻击,如果能攻击所有的行或者能攻击所有的列,那么矩形被攻陷

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<cstdio>
#include<cstring>
int main()
{
	int t;
	int hang[100010],lie[100010];
	scanf("%d",&t);
	while(t--)
	{
		int n,m,k,q;
		scanf("%d%d%d%d",&n,&m,&k,&q);
		memset(hang,0,sizeof(hang));
		memset(lie,0,sizeof(lie)); 
		int x,y;
		for(int i=1;i<=k;i++)
		{
			scanf("%d%d",&x,&y);
			hang[x]=1;
			lie[y]=1;//标记车的行列坐标 
		}
		for(int i=1;i<=n;i++)
		{
			hang[i]+=hang[i-1];//累加和 算出所有车能攻击多少行 
			lie[i]+=lie[i-1];//能攻击的列数 
		 } 
		 int x1,x2,y1,y2;
		 for(int i=1;i<=q;i++)
		 {
		 	scanf("%d%d%d%d",&x1,&y1,&x2,&y2); 
		 	if(x2-x1+1==hang[x2]-hang[x1-1]||y2-y1+1==lie[y2]-lie[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、付费专栏及课程。

余额充值