问题描述
样例输入
3 4
0 0 4 4
1 1 5 5
2 2 6 6
1 1
0 0
4 4
0 5
样例输出
2
1
1
IGNORED
代码
#include <iostream>
using namespace std;
/*
window结构体:表示窗口的范围
point_in_rectangle函数:表示点击的位置在不在某一个窗口中
主函数:接受输入,产生输出
*/
typedef struct{
int x1, y1;
int x2, y2;
}Window;
bool point_in_rectangle(int x, int y, int x1, int y1, int x2, int y2){
return x>=x1 && x<=x2 && y>=y1 && y<=y2;
}
int main(){
int N, M;
scanf("%d %d", &N, &M);
Window window[N];
int window_order[N];
for(int i = 0; i < N; i++){
scanf("%d %d %d %d", &window[i].x1, &window[i].y1, &window[i].x2, &window[i].y2);
window_order[i] = i;
}
for(int i = 0; i < M; i++){
int x, y;
int clicked_window = -1;
scanf("%d %d", &x, &y);
for(int j = N-1; j >= 0; j--){
int candidate = window_order[j];
if(point_in_rectangle(x, y, window[candidate].x1, window[candidate].y1, window[candidate].x2, window[candidate].y2)){
clicked_window = candidate; //当前选中的窗口
for(int k = j+1; k<=N-1 ; k++){ //在选中窗口上面的窗口都往下移一位
window_order[k-1] = window_order[k];
}
window_order[N-1] = clicked_window;//选中窗口移动到最上层
break;
}
}
if(clicked_window != -1){
printf("%d\n",clicked_window+1);//clicked_window表示选中窗口的index,index从0开始,序号从1开始,所以输出序号要+1
} else {
printf("IGNORED\n");
}
}
return 0;
}