问题描述
在某图形操作系统中,有 N 个窗口,每个窗口都是一个两边与坐标轴分别平行的矩形区域。窗口的边界上的点也属于该窗口。窗口之间有层次的区别,在多于一个窗口重叠的区域里,只会显示位于顶层的窗口里的内容。
当你点击屏幕上一个点的时候,你就选择了处于被点击位置的最顶层窗口,并且这个窗口就会被移到所有窗口的最顶层,而剩余的窗口的层次顺序不变。如果你点击的位置不属于任何窗口,则系统会忽略你这次点击。
现在我们希望你写一个程序模拟点击窗口的过程。
输入格式
输入的第一行有两个正整数,即 N 和 M。(1 ≤ N ≤ 10,1 ≤ M ≤ 10)
接下来 N 行按照从最下层到最顶层的顺序给出 N 个窗口的位置。 每行包含四个非负整数 x1, y1, x2, y2,表示该窗口的一对顶点坐标分别为 (x1, y1) 和 (x2, y2)。保证 x1<x2 , y1<y2。
接下来 M 行每行包含两个非负整数 x, y,表示一次鼠标点击的坐标。
题目中涉及到的所有点和矩形的顶点的 x, y 坐标分别不超过 2559 和 1439。
输出格式
输出包括 M 行,每一行表示一次鼠标点击的结果。如果该次鼠标点击选择了一个窗口,则输出这个窗口的编号(窗口按照输入中的顺序从 1 编号到 N);如果没有,则输出"IGNORED"(不含双引号)。
样例输入
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
//存储窗口的坐标和位次
import java.util.Scanner;
public class Windows {
int x1;
int y1;
int x2;
int y2;
int no;
public Windows(int x1, int y1, int x2, int y2, int no) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
this.no = no;
}
public boolean isPointInWindow(int x,int y) {
return (x>=this.x1&&x<=this.x2&&y>=this.y1&&y<=this.y2);
}
}
//实现输入、判断、输出
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int window_count= scanner.nextInt();
int click_count=scanner.nextInt();
List<Windows> windowsList=new ArrayList<>();
for (int i=0;i<window_count;i++){
int x1= scanner.nextInt();
int y1= scanner.nextInt();
int x2= scanner.nextInt();
int y2= scanner.nextInt();
Windows windows=new Windows(x1,y1,x2,y2,i+1);
windowsList.add(windows);
}
for (int i=0;i<click_count;i++){
int x= scanner.nextInt();
int y= scanner.nextInt();
int lastIndex=windowsList.size()-1;
boolean bFind=false;
for (;lastIndex>=0;lastIndex--){
Windows windows=windowsList.get(lastIndex);
if (windows.isPointInWindow(x,y)){
System.out.println(windows.no);
windowsList.remove(lastIndex);
windowsList.add(windows);
bFind=true;
break;
}
}
if (bFind==false){
System.out.println("IGNORED");
}
}
}
}