Title Description:
In preparation for a unique award ceremony, the organizer laid some rectangular carpets on a rectangular area of the venue (which can be seen as the first quadrant of a planar Cartesian coordinate system), with a total of n carpets, numbered from 1 to N. The carpets are now laid out in the order of the numbers from small to large, and the carpets on the front floor are covered in the carpet.
After the carpet is laid, the organizer wants to know the number of the top carpet that covers a point on the ground. Note: The points on the rectangular carpet boundary and the four vertices are also covered by carpets.
Input:
A total of n+2 rows. The first line has an integer n, which indicates a total of n carpets. In the next n rows, the I+1 line represents the information for the number I carpet, containing four positive integer a,b,g,k, separated by a space between each two integers, representing the coordinates (a, b) of the lower-left corner of the carpet and the length of the carpet in the X-and y-axis directions.
The n+2 line contains two positive integers x and y, representing the coordinates (x, y) of the point of the ground being asked.
Output:
A total of 1 rows, an integer representing the number of the carpet being asked for, and 1 if the carpet is not covered here.
Sample input:
3
1 0 2 3
0 2 3 3
2 1 3 3
2 2
Sample output:
3
Tips:
Data range:
30% n<=2
50% 0<=a,b,g,k<=100
100% 0<=n<=10000, 0<=a,b,g,k<=100000
Code:
#include <iostream>using namespace Std;int main () { int n,a[10001],b[10001],x[10001],y[10001],xi,yi; cin>>n; for (int i=1;i<=n;i++) {cin>>a[i]>>b[i]>>x[i]>>y[i]; The lower left corner coordinates are (A[i],b[i]), the transverse length is x[i], and the longitudinal length is y[i] } cin>>xi>>yi; Point (Xi,yi) at the top of the carpet number for (int i=n;i>0;i--) //From the top of the carpet start on the N-carpet check whether the overlay point (Xi,yi), if the overwrite immediately stop {if ( A[i]<=xi && a[i]+x[i]>=xi && b[i]<=yi && b[i]+y[i]>=yi) {cout<<i; return 0;} } cout<<-1; If the blanket (xi,yi) is not found, output the specified message return 0;
NOIP2011 Carpet