[NOIP2011 d1t1] Shop Carpet carpet

Source: Internet
Author: User

NOIP2011 d1t1 Carpet Carpet time limit: 1 Sec Memory Limit: MB
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

Enter a total n+2 line.
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

Outputs a total of 1 lines, an integer representing the number of the carpet being asked for, or 1 if the carpet is not covered.

Sample input
31 0 2 30 2 3 32 1 3 32 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

NOIP2011 DAY1 Carpet

Exercises

Learn Huang Long blog I also have to brush up from scratch Orzhzwer

Well, just do the O (n).

1#include <stdio.h>2 using namespacestd;3 intx,y,a[10010],b[10010],g[10010],k[10010],n,p=-1;4 intMain () {5scanf"%d",&n);6      for(intI=1; i<=n;++i)7scanf"%d%d%d%d",&a[i],&b[i],&g[i],&k[i]);8scanf"%d%d",&x,&y);9      for(intI=1; i<=n;++i)Ten         if(a[i]<=x&& (A[i]+g[i]) >=x&&b[i]<=y && (B[i]+k[i]) >=y) p=i; Oneprintf"%d\n", p); A     return 0; -}
View Code

if the number of queries, reached 105, then O (nm) will explode, we can be processed offline.

Sort the queries and then use the line tree to maintain them. (by Hzwer's blog)

[NOIP2011 d1t1] Shop Carpet carpet

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.