BZOJ1113 poster PLA

Source: Internet
Author: User

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

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.