• P1830 轰炸III


    题目背景

    一个大小为N*M的城市遭到了X次轰炸,每次都炸了一个每条边都与边界平行的矩形。

    题目描述

    在轰炸后,有Y个关键点,指挥官想知道,它们有没有受到过轰炸,如果有,被炸了几次,最后一次是第几轮。

    输入格式

    第一行,四个整数:n、m、x、y。

    以下x行,每行四个整数:x1、y1、x2、y2,表示被轰炸的矩形的左上角坐标和右下角坐标(比如1 3 7 10就表示被轰炸的地方是从(1,3)到(7,10)的矩形)。

    再以下y行,每行两个整数,表示这个关键点的坐标。

    输出格式

    共y行,

    每行第一个字符为Y或N,表示是否被轰炸,若为Y,在一个空格后为两个整数,表示被炸了几次和最后一次是第几轮。

    输入输出样例

    输入 #1复制
    10 10 2 3
    1 1 5 5
    5 5 10 10
    3 2
    5 5
    7 1
    
    输出 #1复制
    Y 1 1
    Y 2 2
    N
    

    说明/提示

    数据很弱!!!直接模拟!!!!

    1<=N,M<=100

    代碼

    #include<stdio.h>
    
    int main() {
        int n, m, x, y;
        scanf("%d %d %d %d", &n, &m, &x, &y);
        int Boom[x][4];         //轟炸區域 x1y1 01, x2y2 23
        int KeyArea[y][5];      //關鍵點陣列,0是否轟炸,12坐標,3被轟炸次數,4最後一次被轟炸編號
        for (int i = 0;i < x;i++) {
            for (int j = 0;j < 4;j++) {
                scanf("%d", &Boom[i][j]);
                /*if (Boom[i][0] < 0) {
                    Boom[i][0] = 0;
                }
                if (Boom[i][1] < 0) {
                    Boom[i][1] = 0;
                }
                if (Boom[i][2] > m-1) {
                    Boom[i][2] = m-1;
                }
                if (Boom[i][3] > n-1) {
                    Boom[i][3] = n-1;
                }*/
            }
        }//保存x行轟炸區
    
        for (int i = 0;i < y;i++) {
            for (int j = 1;j < 3;j++) {
                scanf("%d", &KeyArea[i][j]);
                KeyArea[i][0] = 0;
                KeyArea[i][3] = 0;
            }
        }//保存y行關鍵點數據
    
        for (int i = 0;i < y;i++) {         //掃描KeyArea
            for (int j = 0;j < x;j++) {     //掃描Boom
    
                if (   KeyArea[i][1] >= Boom[j][0]
                    && KeyArea[i][1] <= Boom[j][2]
                    && KeyArea[i][2] >= Boom[j][1]
                    && KeyArea[i][2] <= Boom[j][3]) {//判斷每個關鍵點是否位於轟炸區内
    
                    KeyArea[i][0] = 1;
                    KeyArea[i][3]++;
                    KeyArea[i][4] = j+1;//每次被轟炸后 將轟炸編號覆蓋
                }//if
            }//for
        }
        for (int i = 0;i < y;i++) {
            if (KeyArea[i][0] == 1) {
                printf("Y %d %d
    ",KeyArea[i][3],KeyArea[i][4]);
            }
            else {
                printf("N
    ");
            }
        }
        return 0;
    }
    

    编程语言C++

    代码长度1.87KB

    用时12ms

    内存624.00KB

  • 相关阅读:
    判断一个数组是不是一维数组
    XML5个转义符:<,>,&,”,©;的转义字符分别如下: &lt; &gt;&amp; &quot; &apos;
    linux crontab & 每隔10秒执行一次
    微信企业号-根据code获取成员信息(过期code)
    Namespace declaration statement has to be the very first statement in the script-去除bom头
    去掉一个字符前面的全部0
    检查一个数字是否为个位数
    nginx配置location总结及rewrite规则写法
    QT 4.7支持中文(QT4.7)(中文)(makeqpf)
    【转】vlc android 代码编译
  • 原文地址:https://www.cnblogs.com/rrrrraulista/p/14221460.html
Copyright © 2020-2023  润新知