思路:
1、 创建数组x[n][2],y[n][2]存放每个窗口的两个坐标。
2、xm[m]存放判断的坐标,index[n+1]来存放对应窗口的优先级,这里用数字表示,数字越大,优先级越高。
3、遍历,求符合要求的窗口,用index【】来判断,取优先级大的下标。
该下标对应的就是符合题意的窗口。如果没有,则输出“IGNORED”.
import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner input = new Scanner(System.in);int n = input.nextInt();int m = input.nextInt();int nc = n; // 用来做优先级int max = 0;boolean flag = false;int[][] x = new int[n][2];int[][] y = new int[n][2];int[] index = new int[n+1];int[] xm = new int[m];int[] ym = new int[m];for (int i = 0;i < n; i++){x[i][0] = input.nextInt();y[i][0] = input.nextInt();x[i][1] = input.nextInt();y[i][1] = input.nextInt();index[i+1] = i+1;}for (int i = 0; i < m;i++){xm[i] = input.nextInt();ym[i] = input.nextInt();}for (int i = 0;i < m; i++){flag = false;max = 0;for (int j = 0; j < n;j++){if (x[j][0]<=xm[i]&&x[j][1]>=xm[i]&&y[j][0]<=ym[i]&&y[j][1]>=ym[i]){flag = true;if (index[j+1] > index[max]){max = j+1;}}}if (!flag){System.out.println("IGNORED");continue;}System.out.println(max);index[max] = ++nc;}}
}
原题链接:http://118.190.20.162/view.page?gpid=T9