【洛谷OJ】【JAVA】P1003 铺地毯

36 篇文章 0 订阅

https://www.luogu.org/problemnew/show/P1003

import java.util.Iterator;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	private static Scanner cin;
	
	public static void main(String args[]) throws Exception {
		cin = new Scanner(System.in);
		int n = cin.nextInt();
		LinkedList<Carpet> carpets = new LinkedList<Carpet>();
		int a,b,g,k;
		for(int i=1; i<=n; i++) {
			a = cin.nextInt();
			b = cin.nextInt();
			g = cin.nextInt();
			k = cin.nextInt();
			carpets.addFirst(new Carpet(i,a,b,g,k));
		}
		int x = cin.nextInt();
		int y = cin.nextInt();
		Iterator<Carpet> it = carpets.iterator();
		int ret = -1;
		while(it.hasNext()) {
			Carpet carpet = (Carpet)it.next();
			if(carpet.covered(x, y)) {
				ret = carpet.getId();
				break;
			}
		}
		System.out.println(ret);
	}
}

final class Carpet{
	int id,x1,y1,x2,y2;
	public Carpet(int id, int x,int y, int length, int height) {
		this.id = id;
		x1 = x;
		y1 = y;
		x2 = x+length;
		y2 = y+height;
	}
	public boolean covered(int x, int y) {
		boolean ret =false;
		if(x>=x1 && y>=y1 && x<=x2 && y<=y2) {
			ret = true;
		}
		return ret;
	}
	public int getId() {
		return id;
	}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值