Bzoj 1113: [poi2008] Poster PLA

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.