Carpet / Luo Gu P1003

To prepare a special awards ceremony, organizers in a rectangular area of ​​the venue (can be seen as a first quadrant of the rectangular coordinate system) covered with some of the rectangular carpet. A total of n carpets, numbered from 1 to n. Now in accordance with these numbers carpet ascending order successively laid parallel to the axis, after laying carpet overlaid on top of previously laid carpet.

After the completion of the laying of the carpet, the organizers would like to know the carpeting covering the top floor of a number of points. Note: point on the boundary of the rectangle, and four vertices of the carpet can be considered covered by the carpet.

Input

输入共 n+2 行。

第一行,一个整数 n,表示总共有 n 张地毯。

接下来的 n 行中,第 i+1 行表示编号 i 的地毯的信息,包含四个正整数 a,b,g,k,每两个整数之间用一个空格隔开,分别表示铺设地毯的左下角的坐标 (a,b) 以及地毯在 x 轴和 y 轴方向的长度。

第 n+2 行包含两个正整数 x 和 y,表示所求的地面的点的坐标 (x,y)。

Output

输出共 1 行,一个整数,表示所求的地毯的编号;若此处没有被地毯覆盖则输出-1

Sample Input 1

3
1 0 2 3
0 2 3 3
2 1 3 3
2 2

Sample Output 1

3

Sample Input 2

3
1 0 2 3
0 2 3 3
2 1 3 3
4 5

Sample Output 2

-1

Description / Tips

img

answer

x[i] y[i] xx[i] yy[I]
分别记录这块地毯x轴左端 y轴下端 x轴右端 y周上端
记录下来,给出x,y后
从后往前搜,这样保证了搜到的是最上面的地毯

Code

#include<cstdio>
using namespace std;
const int N = 1e4 + 10;

int n, x[N], y[N], xx[N], yy[N];

int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++){
        scanf("%d%d%d%d", &x[i], &y[i], &xx[i], &yy[i]);
        xx[i] += x[i], yy[i] += y[i];
    }
    int a, b;
    scanf("%d%d", &a, &b);
    for(int i = n; i >= 1; i--){
        if(x[i] <= a && xx[i] >= a && y[i] <= b && yy[i] >= b){
            printf("%d\n", i);
            return 0;
        }
    }
    printf("-1\n");
    return 0;
}

Guess you like

Origin www.cnblogs.com/Little-Turtle--QJY/p/12386774.html