Conturbatio

来源:互联网 发布:mysql-python和mysqldb 编辑:程序博客网 时间:2024/05/16 03:31

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

22 2 1 21 11 1 1 22 1 2 22 2 2 11 11 22 1 2 2

Sample Output

YesNoYes          

Hint

Huge input, scanf recommended.
在一个n*m的方格内,有K个车,它可以攻击它所在的行和列,包括它自己,给你4个点,代表一个矩形的左下和右上的点,问你它是否可以攻击完矩形内的所有方格:
思路,思维题,看代码,自己画图理解;
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int row[100009],col[100009];int main(){int t,n,m,k,q,x1,x2,y1,y2,i,j;int a,b;scanf("%d",&t);while(t--){memset(row,0,sizeof(row));memset(col,0,sizeof(col));scanf("%d%d%d%d",&n,&m,&k,&q);for(i=0;i<k;i++){scanf("%d%d",&a,&b);row[a]=1;col[b]=1;}for(i=1;i<=n;i++)if(row[i]) row[i]+=row[i-1];for(i=1;i<=m;i++)if(col[i]) col[i]+=col[i-1];for(i=0;i<q;i++){scanf("%d%d%d%d",&x1,&y1,&x2,&y2);if(row[x2]>=x2-x1+1||col[y2]>=y2-y1+1)printf("Yes\n");elseprintf("No\n");}}return 0;}

0 0
原创粉丝点击