hdu 5480 Conturbatio【模拟】

75 篇文章 0 订阅

Conturbatio

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


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.

问题描述
在一个n \times mn×m的国际象棋棋盘上有很多车(Rook),其中车可以攻击他所属的一行或一列,包括它自己所在的位置。
现在还有很多询问,每次询问给定一个棋盘内部的矩形,问矩形内部的所有格子是否都被车攻击到?
输入描述
输入文件包含多组数据,第一行为数据组数TT。
每组数据有4个正整数n , m , K , Qn,m,K,QKK为车的数量,QQ为询问的个数。
接下来有KK行,每行两个整数x , yx,y , 表示车所在的坐标。
再接下来有QQ行,每行4个整数x1 , y1 , x2 , y2x1,y1,x2,y2,表示询问的矩形的左下角与右上角的坐标。

1\leq n , m , K , Q \leq 100,0001n,m,K,Q100,000.
1\leq x \leq n , 1 \leq y \leq m1xn,1ym.
1\leq x1 \leq x2 \leq n , 1 \leq y1 \leq y2 \leq m1x1x2n,1y1y2m.
输出描述
对于每组询问,输出Yes或No。

对于题目要求,一个车的一行和一列都是攻击范围,所以我们这里应用两个数组就能够表示整个图,一个用来表示行是否被攻击,一个用来表示列是否被攻击~

输入的时候直接表示这行这列被攻击了即可:

        for(int i=0;i<k;i++)//k个车
        {
            int x,y;
            scanf("%d%d",&x,&y);
            row[x]=1;
            col[y]=1;
        }
然后是询问,我们知道,一个区域如果行被攻击个遍或者是被列攻击个遍,那么就说明,这片区域已经沦落了、比如样例1中的图是这样的:1表示被攻击了的地方,0表示没有

11
10
对于这个样例,我们知道,row和col的数据如下:

row【1】=1;row【2】=0;

col【1】=1;col【2】=0;

样例1中询问1是这样的 1 1 1 2,我们显然看的出来,如果从x1到行x2中的row都是1,或者说从y1到y2中的col都是1,那么这片区域明显都被攻击过了;思路清晰了,这里就要上代码了:

#include<stdio.h>
#include<string.h>
using namespace std;
int row[101010];
int col[101010];
int main()
{
    int t;
    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(int i=0;i<k;i++)
        {
            int x,y;
            scanf("%d%d",&x,&y);
            row[x]=1;
            col[y]=1;
        }
        for(int i=1;i<=n;i++)//优化代码~
        {
            row[i]+=row[i-1];
            col[i]+=col[i-1];
        }
        while(q--)
        {
            int x1,y1,x2,y2;
            scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
            if(x2-x1+1==row[x2]-row[x1-1]||y2-y1+1==col[y2]-col[y1-1])//然后这里用减法代替for循环
            {
                printf("Yes\n");
            }
            else
            {
                printf("No\n");
            }
        }
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值