Los P1003 valley carpeted noip2011 improve group day1T1

Los P1003 valley carpeted noip2011 improve group day1T1 

Luo Gu original title

Title Description

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 and output formats

Input Format

The input common row n + 2

The first line, an integer n, n represents the total Carpet

The next n-th row, the i + 1 represents the number i of information carpet, comprising four positive integers a, b, g, k. Separated by a space between each two integers, represent the lower left carpeted coordinate angle (a, b) in the x-axis and the length of the carpet and the y-axis direction

N + 2 th line contains two positive integers x and y, represents the coordinate point of the request of the ground (x, y)

Output Format

The output common line 1, an integer, representing the number of carpet required; if the carpet is not covered here outputs -1

Sample input and output

Input Sample # 1:
1 0 3 2
0 2 3 3
2 1 3 3
2 2
Output Sample # 1:
3

Input Sample # 2:
. 3
. 1. 3 0 2
0 2. 3. 3
2. 3. 3. 1
. 4. 5
Output Sample # 2:
-1


 answer


Violence Act

This is not the first reaction is violent thing!

1  // Los P1003 Valley Group improved carpet noip2011 day1T1 
2 #include <the iostream>
 . 3  the using  namespace STD;
 . 4  int DM [ 10000 ] [ 10000 ], TA, TB, a Tg of, TK;
 . 5  int main () {
 . 6      int n- , X, Y;
 . 7      CIN >> n-;
 . 8      for ( int I = . 1 ; I <= n-; I ++ ) {
 . 9          CIN >> TA TB >> >> >> a Tg of TK;
 10          for ( int J = TA; J <a Tg of + TA; J ++ )
 . 11          for ( int m=tb;m<tb+tk;m++)
12                 dm[j][m]=i;
13     }
14     cin>>x>>y;
15     if(dm[x][y]) cout<<dm[x][y];
16     else cout<<"-1";
17     return 0;
18 }

 

explain:

dt [10000] [10000] Why not open bigger?

Open int array of two-dimensional array in particular, need to pay attention not to exceed 10 ^ 8

When the output is judged what the hell?

Then nothing important step forward.

The idea is that when I enter every carpet, traversed it in the ground, their values ​​become rug name

So happy ah!

BUT......

Such a long time before the results really have not seen. . .

 

MLE: Memory Limit Exceeded, memory limits.

Luo Valley each state evaluation

# 2 Do you want to see how much?

Because the blog garden can not put txt, I'll just added a suffix (.ppt) up

This is the output

# 2 so big? ! ? ! The number 10000? ? ?

Memory too? Or try to discrete?


Unknown method

Named so hard, give me a break. . .

Well in fact, I do not always go traversal traversal, if there are ten thousand carpets, carpet each size in 1000 * 1000, it would mean that a total of 10 ^ 10 times to traverse?

Why not each four array data in the carpet (a, b, g, k), and then determine (x, y) is not within the scope of the carpet?

1  // Los P1003 Valley Group improved carpet noip2011 day1T1 
2 #include <the iostream>
 . 3  the using  namespace STD;
 . 4  int main () {
 . 5      int n-, X, Y, XY = - 1 ;
 . 6      CIN >> n-;
 . 7      int A [n-], B [n-], G [n-], K [n-];
 . 8      for ( int I = . 1 ; I <= n-; I ++ )
 . 9          CIN >> A [I- . 1 ] >> B [I - . 1 ] >> G [I- . 1 ] >> K [I- . 1 ];
 10      CIN >> >> X Y;
 . 11      for (int j=1;j<=n;j++){
12         if(a[j-1]<=x&&a[j-1]+g[j-1]>=x)
13         if(b[j-1]<=y&&b[j-1]+k[j-1]>=y)
14             xy=j;
15     }
16     cout<<xy;
17     return 0;
18 }

 

This approach is different from the previous one of the biggest, violent method can get the top number of each carpet coordinate, and "unknown methods" have only a (x, y) of carpet, regardless of others. Have their own advantages and disadvantages, right?

 

There is a small pit

When I think of "unknown methods", why not like violence law that, while input a, b, g, k, side judge (x, y) in the interior is not it?

Since the final output when x and y. . . . . .


Further improvements

Method Two (good name not want to play long, the following are the same), the second for loop is from 1 ~ n's.

But we want is a final carpet ah!

Backwards loop chant?

1  // Los P1003 Valley Group improved carpet noip2011 day1T1 
2 #include <the iostream>
 . 3  the using  namespace STD;
 . 4  int main () {
 . 5      int n-, X, Y, XY = - 1 ;
 . 6      CIN >> n-;
 . 7      int A [n-], B [n-], G [n-], K [n-];
 . 8      for ( int I = . 1 ; I <= n-; I ++ )
 . 9          CIN >> A [I- . 1 ] >> B [I - . 1 ] >> G [I- . 1 ] >> K [I- . 1 ];
 10      CIN >> >> X Y;
 . 11      for (int j=n;j>=1;j--){
12         if(a[j-1]<=x&&a[j-1]+g[j-1]>=x)
13         if(b[j-1]<=y&&b[j-1]+k[j-1]>=y)
14         {
15             xy=j;
16             break;
17         }
18     }
19     cout<<xy;
20     return 0;
21 }

 Ah ha ha ha genius like me!


To a question made the three methods. . . I am not a god? ? ?

Guess you like

Origin www.cnblogs.com/send-off-a-friend/p/11138847.html