[Bai Lian oj] 4033: Laying carpet

4033: Carpet

describe

To prepare for a unique awards ceremony, the organizers laid out some rectangular rugs in a rectangular area of ​​the venue (which can be thought of as the first quadrant of the rectangular coordinate system of the plane). There are a total of n carpets, numbered from 1 to n. Now lay these rugs parallel to the coordinate axis in the order from small to large, and the rugs laid in the back cover the rugs that have been laid in the front.
After the carpet is laid, the organizer wants to know the number of the top carpet covering a certain point on the ground. Note: Points on the border of the rectangular rug and on the four vertices are also counted as covered by the rug.

enter
Enter a total of n+2 lines. 
The first line, an integer n, means there are n rugs in total. 
In the next n lines, the i+1th line represents the information of the carpet number i, including four positive integers a, b, g, k, separated by a space between each two integers, respectively indicating the number of carpets laid. The coordinates (a, b) of the lower left corner and the length of the carpet in the x- and y-axis directions. 
Line n+2 contains two positive integers x and y, representing the coordinates (x, y) of the point on the ground to be sought.
output
Output a total of 1 line, an integer, indicating the number of the required carpet; if there is no carpet here, output -1.
sample input
3
1 0 2 3
0 2 3 3
2 1 3 3  
2 2
Sample output
3
hint
[Input and output example description] 
As shown in the figure above, the carpet No. 1 is represented by a solid line, the carpet No. 2 is represented by a dotted line, and the carpet No. 3 is represented by a double solid line. The top carpet covering the points (2, 2) is the carpet No. 3 .
#include<stdio.h>
int main(){
    int n,k=-2,i;
    scanf("%d",&n);
    int a[n],b[n],x[n],y[n],x0,y0;
    for(i=0;i<n;i++){
        scanf("%d %d %d %d",&a[i],&b[i],&x[i],&y[i]);
    }
    scanf("%d %d",&x0,&y0);
    for(i=0;i<n;i++){
        if(x0>=a[i]&&x0<=a[i]+x[i]&&y0>=b[i]&&y0<=b[i]+y[i])k=i;
    }
    printf("%d",k+1);
    return 0;
}



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324515473&siteId=291194637