hdoj Conturbatio 5480 (数组模拟+技巧) 好题

来源:互联网 发布:淘宝首页添加热点 编辑:程序博客网 时间:2024/05/21 21:04

Conturbatio

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


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
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.
 
题目大意:有t组测试数据,每组给一个n * m的矩形棋盘格子,棋盘内有很多车(x, y),每个车的攻击范围是这个车所在的行x和列y,共有K辆车,然后有Q次询问,每次询问给一个矩形(四个数描述矩形,左下角和右上角),问给的矩形的每个格子都能否被车攻击,是就输出“Yes”,否则“No”。
//http://blog.csdn.net/Royecode/article/details/48877225,参考的大神的博客
//机智的解法 ,参考大神的 #include<stdio.h>#include<string.h>#include<algorithm>#define N 100010using namespace std;int row[N],col[N];int main(){int t,i;scanf("%d",&t);while(t--){memset(row,0,sizeof(row));memset(col,0,sizeof(col));int n,m,k,q;scanf("%d%d%d%d",&n,&m,&k,&q);for(i=0;i<k;i++){int x,y;scanf("%d%d",&x,&y);row[x]=col[y]=1;//将车的点的横纵坐标标记为1. }for(i=1;i<=n;i++)//将车所在的行全标记为1。 if(row[i])row[i]+=row[i-1];for(i=1;i<=m;i++)//将车所在的列全标记为1. if(col[i])col[i]+=col[i-1];for(i=0;i<q;i++){int x1,x2,y1,y2;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