一、题目链接
http://noi.openjudge.cn/ch0109/14/
二、解题思路
三、实施步骤
四、Java程序
import java.util.Scanner;
class Carpet {
private int x;
private int y;
private int width;
private int height;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
}
public class Main {
public int topCarpet(Carpet[] carpets, int x, int y) {
int n = carpets.length;
int ans = -1;
for (int i = 0; i < n; i++) {
if (x >= carpets[i].getX() && y >= carpets[i].getY()
&& x <= carpets[i].getX() + carpets[i].getWidth()
&& y <= carpets[i].getY() + carpets[i].getHeight()) {
ans = i + 1;
}
}
return ans;
}
public static void main(String[] args) {
Main test = new Main();
Scanner input = new Scanner(System.in);
int n = input.nextInt();
Carpet[] carpets = new Carpet[n];
for (int i = 0; i < n; i++) {
carpets[i] = new Carpet();
carpets[i].setX(input.nextInt());
carpets[i].setY(input.nextInt());
carpets[i].setWidth(input.nextInt());
carpets[i].setHeight(input.nextInt());
}
int x = input.nextInt();
int y = input.nextInt();
System.out.print(test.topCarpet(carpets, x, y));
}
}