1113: [Poi2008] Poster pla

Source: Internet
Author: User

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

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.