看来以前题目的数据规模可能都不大,在等报错和超时的时候居然蹦出来100分。
虽然使用的是数组,但是还是觉得为了避免太多的数据移动,用链表实现可能更好一点。
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int N = in.nextInt();
int M = in.nextInt();
int[][] windows = new int[N][5];
String[] s = new String[N];
int num =0;
for(int i =0;i<N;i++) {
windows[i][0] = in.nextInt();//x1
windows[i][1] = in.nextInt();//y1
windows[i][2] = in.nextInt();//x2
windows[i][3] = in.nextInt();//y2
windows[i][4] = i+1;//窗口编号
}
for(int i =0;i<M;i++) {
int x = in.nextInt();
int y = in.nextInt();
boolean flag = false;
for(int j =N-1;j>=0;j--) {//向上遍历
if(x>=windows[j][0]&& x <=windows[j][2] && y>=windows[j][1]&& y<=windows[j][3] ) {//点中了窗口
System.out.println(windows[j][4]);
flag = true;
if(j == N-1) break;
//移动窗口位置
int x1 = windows[j][0];
int y1 = windows[j][1];
int x2 = windows[j][2];
int y2 = windows[j][3];
int number = windows[j][4];
for(int p = j;p<N-1;p++) {
windows[p][0] = windows[p+1][0];
windows[p][1] = windows[p+1][1];
windows[p][2] = windows[p+1][2];
windows[p][3] = windows[p+1][3];
windows[p][4] = windows[p+1][4];
}
windows[N-1][0] = x1;
windows[N-1][1] = y1;
windows[N-1][2] = x2;
windows[N-1][3] = y2;
windows[N-1][4] = number;
break;
}
}
if(!flag) {
System.out.println("IGNORED");
}
}//for
in.close();
}
}