1113: [Poi2008] Poster pla time limit:10 Sec Memory limit:162 MB
submit:765 solved:466
[Submit] [Status] [Discuss] Description
n rectangles, lined up in a row. Now you want to cover them with as few rectangular posters as possible.
Input
The first line gives the number n, which means there are n rectangles. N under [1,250000] n rows, each row gives the length and width of the rectangle. Its value in [1,1000000000]2 postering
Output
The minimum number of posters.
Sample Input5
1 2
1 3
2 2
2 5
1 4
Sample Output4
HINT Source
The puzzle: A cute and monotonous stack, explained below (obviously, the width of what does not know the role of where = =, acknowledgements zyf-zyf god Ben, Wish rp++, abuse Farm + +)
Exercises
Ans is at most equal to N, so under what circumstances can ans be reduced?
First, if it is reduced, it must be a poster, covering two rectangles of the same height (width is soy sauce ...). )
So if H[I]=H[J] then you have to make sure that I and J are no taller than they are.
Hey? Think of what, right, monotonous stack! Maintains a monotonically decreasing stack when the element = Stack top element is ans--, and the stack top element is bounced
1/**************************************************************2Problem:11133 User:hansbug4 language:pascal5 result:accepted6Time:3884Ms7Memory:8040KB8****************************************************************/9 Ten var One I,k,l,m,n:longint;j:int64; AA:Array[0..1000005] ofInt64; - begin -READLN (n); l:=n;k:=0; the fori:=1 toN Do - begin - readln (j,j); - whileJ<=A[K] Do + begin - ifJ=A[K] ThenDec (l); + Dec (k); A End; atInc (k); a[k]:=J; - End; - Writeln (l); - End.
1113: [Poi2008] Poster pla