Question 1113: [poi2008] Poster platime limit: 10 sec memory limit: 162 MB
Description
N rectangles are arranged in a row. Now we want to cover them with a small number of rectangular posters.
Input
The first line gives the number N, which indicates that there are n rectangles. N is in the N rows under [1/2], and each line gives the length and width of the rectangle. Its value is in [] 2 postering
Output
The minimum number of posters.
Sample input5
1 2
1 3
2 2
2 5
1 4
Sample output4
Question
We can use the same poster to cover this question as soon as there is a height, but the two posters can only be pasted separately. Based on this idea, we can write a monotonous stack.
Code
1 /*Author:WNJXYK*/ 2 #include<cstdio> 3 using namespace std; 4 int t,x,n,s[250001],top,ans; 5 int main(){ 6 scanf("%d",&n); 7 for(int i=1;i<=n;i++){ 8 scanf("%d%d",&t,&x); 9 while(x<=s[top]){10 if(x==s[top])ans++;11 top--;12 }13 s[++top]=x;14 }15 printf("%d",n-ans);16 return 0;17 }
View code
Bzoj 1113: [poi2008] Poster PLA