Seems to be a very old question? The problem is not found on bzoj, so it is not submitted.
1113: [Poi2008] Poster pla time limit:10 Sec Memory limit:162 MB
submit:810 solved:507
[Submit] [Status] [Discuss] Description
n rectangles, lined up in a row. Now you want to cover them with as few rectangular posters as possible.
(Silvern Note: No poster can be posted outside the rectangle)
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
According to the mysterious hints can be processed with a monotone stack.
Let's assume that each rectangle is covered with a poster. From left to right, for a rectangle, if there is a rectangle with its height equal to the left (and there is no lower between the two rectangles), then a large poster can be used to cover the two rectangles and the part between them (see), the total number of posters--。
Maintain the "left first rectangle lower than the current rectangle" with a monotonic stack, if the rectangle is the same height as the current rectangle, then the total number of posters--
The code is as follows:
1#include <cstdio>2#include <iostream>3#include <cmath>4 using namespacestd;5 intN;6 intst[ -];7 intt=0;8 intans;9 intMain () {Tenscanf"%d",&n); OneAns=n;//worst case need n Zhang Hai report A inti,j; - intx, y; -scanf"%d%d",&x,&y); thest[++t]=y; - for(i=2; i<=n;i++){ -scanf"%d%d",&x,&y); - while(t>0&& st[t]>y) t--; + if(st[t]==y) ans--; -st[++t]=y; + } Aprintf"%d\n", ans); at return 0; - -}
BZOJ1113 poster PLA