金科——铺地毯

在这里插入图片描述

import java.util.Scanner;

public class Carpet {
	public static void main(String[] args) {
		Scanner scan  = new Scanner(System.in);
		int n = scan.nextInt();
		int ar[][] = new int[n][4];
		for(int i=0;i<n;i++)
		{
			int a = scan.nextInt();
			int b = scan.nextInt();
			int g = scan.nextInt();
			int k = scan.nextInt();
			
			ar[i][0] =a; 
			ar[i][1] =b;
			ar[i][2]=a+g;
			ar[i][3]=b+k;
		}
		
		int x =scan.nextInt();
		int y =scan.nextInt();
		int  t =0;
		int result=0;
		for(int i =n-1;i>=0&&t==0;i--)
		{ 
			if(x>=ar[i][0]&&x<=ar[i][2]&&y>=ar[i][1]&&y<=ar[i][3])
			{
				t=1;
				result = i+1;
			}
		}
		if(t==0)
			System.out.println(-1);
		else
			System.out.println(result);
		
	}

}

猜你喜欢

转载自blog.csdn.net/adityasaber/article/details/82817354