CSP 201403-2 窗口 Java

数据量很小,直接模拟

import java.util.*;

class Window {
    
    
    int id;
    int x1;
    int y1;
    int x2;
    int y2;
    public Window (int id, int x1, int y1, int x2, int y2) {
    
     
        this.id = id;
        this.x1 = x1;
        this.y1 = y1;
        this.x2 = x2;
        this.y2 = y2;
    }
}

public class Main{
    
    
    public static void main(String[] args) {
    
    
        Scanner input = new Scanner(System.in);
        
        int n = input.nextInt();
        int m = input.nextInt();
        Window[] windows = new Window[n];
        for (int i = 0; i < n; i++) {
    
    
            windows[i] = new Window(i + 1, input.nextInt(), input.nextInt(), input.nextInt(), input.nextInt());
        }
            
        for (int i = 0; i < m; i++) {
    
    
            int x = input.nextInt();
            int y = input.nextInt();
            
            int loc = judge(x, y, windows);
            if (loc == -1) {
    
    
                System.out.println("IGNORED");
            } else {
    
    
                System.out.println(windows[loc].id);
                Window temp = windows[loc];
                for (int j = loc + 1; j < windows.length; j++) {
    
    
                    windows[j -1] = windows[j];
                }
                windows[windows.length - 1] = temp;
            }
        }
        
        input.close();
    }
    private static int judge(int x, int y, Window[] windows) {
    
    
        for (int i = windows.length - 1; i >= 0; i--) {
    
    
            if(x >= windows[i].x1 && x <= windows[i].x2 && y >= windows[i].y1 && y <= windows[i].y2) {
    
    
                return i;
            }
        }
        return -1;
    }
}

猜你喜欢

转载自blog.csdn.net/qq_43349112/article/details/115018138