Recently in writing noip2011 problem, prepare for Noip, first add an oil to yourself!
The following is noip2011 's questions and his own problem-solving report, hope to be helpful to everyone, topic 1 as follows
1. Carpet laying
(Carpet.cpp/c/pas)
"Problem description"
In order to prepare a unique award ceremony, the organizer is in a rectangular area of the venue (can be seen as a planar Cartesian
The first quadrant of the system) is paved with some rectangular carpets. A total of n carpets, numbered from 1 to N. Now put these carpets in accordance with
Numbering from small to large in the order of parallel to the axis has been laid, after the carpet covered in front of the carpet has been paved.
After the carpet is laid, the organizer wants to know the number of the top carpet that covers a point on the ground. Note: in the rectangle
Carpet boundaries and points on the four vertices are also covered by carpets.
Input
The input file name is carpet.in.
Enter a total n+2 line.
The first line, an integer n, indicates a total of n carpets.
In the next n rows, the I+1 line represents the carpet information for number I, containing four positive integer a,b,g,k, each
Two integers separated by a space, indicating the coordinates (a, b) of the lower-left corner of the carpet and the
The length of the axis and y-axis direction.
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
The output file name is Carpet.out.
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.
"Input and output Example 1"
Carpet.in Carpet.out
3
1 0 2 3
0 2 3 3
2 1 3 3
2 2
3
"Input and Output sample description"
For example, the 1th carpet with a solid line, 2nd carpet with a dashed line, 3rd is indicated by a double solid lines, covering point (2,
2) on the top of the carpet is the Carpet No. 3rd.
X
Y
"Input and output Example 2"
Carpet.in Carpet.out
3
1 0 2 3
0 2 3 3
2 1 3 3
4 5
-1
"Input and Output sample description"
For example, the 1th carpet with a solid line, 2nd carpet with a dashed line, 3rd with a double solid lines, point (4,5)
Not covered by carpet, so output-1.
"Data Range"
For 30% of the data, there are n≤2;
For 50% data, 0≤a, B, G, k≤100;
For 100% of the data, there are 0≤n≤10,000,0≤a, B, G, k≤100,000.
The first response is that the line tree maintenance = =
Later it was found that only one value was required, and the arrangement was sequential 233333
Idea: With a huge (also not much, 4*x on the line) of the array to save all the reading data, and then from the back to the next judgement can be, once the horizontal axis min<= the <= axis Max and ordinate the same satisfaction, directly out of the output is good
Paste the following code:
varF:Array[0..4,0..23333] ofLongint; Fx,fy:longint; I,j,k,l,m,n,o,p,a,b:longint; beginREADLN (n); fori:=1 toN DoRead (f[1][i],f[2][i],f[3][i],f[4][i]); Read (FX,FY); A:=-1; forI:=nDownto 1 Do if(f[1][I]<=FX) and(fx<=f[1][i]+f[3][i]) and(f[2][I]<=FY) and(fy<=f[2][i]+f[4][i]) Then beginA:=i; Break End; Writeln (a); End.
[noip2011] Carpet (carpet) Problem solving report