CCF 20140302 窗口

思路:以窗口为结构体,包含窗口id,所在层数layer,x1,x2,y1,y2。将所有窗口按层数从大到小排序,为了方便从最上层筛选点击的窗口;筛选到符合条件的窗口,break,在找到符合条件之前的所有窗口都减一。

#include <iostream>
#include <algorithm>

using namespace std;

const int N = 10;
struct win{
    int id;
    int layer;
    int x1,x2,y1,y2;
};
win w[N];

bool cmp(win w1,win w2){
    return w1.layer > w2.layer;
}
int main(){
    int n,m;
    cin>>n>>m;
    for(int i = 0; i < n; i++){
        cin>>w[i].x1>>w[i].y1>>w[i].x2>>w[i].y2;
        w[i].id = i + 1;
        w[i].layer = i + 1;
    }

    for(int i = 0; i < m; i++){
        int x,y;
        cin>>x>>y;
        int j;
        //按层数从大到小排序,先从顶层筛选符合条件的
        sort(w,w+n,cmp);
        for(j = 0; j < n; j++){
            if(w[j].x1 <= x && x <= w[j].x2 &&
               w[j].y1 <= y && y <= w[j].y2){
                cout<<w[j].id<<endl;
                w[j].layer = n;
                break;//找到后跳出,后面的不动
            }
            else{//在找到符合条件的窗口之前的窗口的层数都--
                w[j].layer--;
            }
        }
        if(j == n)
            cout<<"IGNORED"<<endl;
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值