BZOJ——T 1113: [Poi2008]海报PLA

http://www.lydsy.com/JudgeOnline/problem.php?id=1113

Time Limit: 10 Sec  Memory Limit: 162 MB
Submit: 1170  Solved: 792
[Submit][Status][Discuss]

Description

N个矩形,排成一排. 现在希望用尽量少的矩形海报Cover住它们.

Input

第一行给出数字N,代表有N个矩形.N在[1,250000] 下面N行,每行给出矩形的长与宽.其值在[1,1000000000]2 1/2 Postering

Output

最少数量的海报数.

Sample Input

5
1 2
1 3
2 2
2 5
1 4

Sample Output

4

HINT

 

Source

 

宽度并没有什么用。。。

可以用容斥原理   ans==n-可以省略的个数

维护一个单调增栈,如果栈中有高度大于下一个高度的,省略个数++

 1 #include <algorithm>
 2 #include <cstdio>
 3 
 4 using namespace std;
 5 
 6 const int N(252333);
 7 int stack[N],top,ans;
 8 
 9 inline void read(int &x)
10 {
11     x=0; int ch=getchar();
12     for(;ch>'9'||ch<'0';) ch=getchar();
13     for(;ch>='0'&&ch<='9';ch=getchar()) x=ch-'0'+x*10;
14 }
15 
16 int main()
17 {
18     int n,w,h; read(n);
19     ans=n;
20     for(int i=1;i<=n;i++)
21     {
22         read(w),read(h);
23         for(;top>0&&stack[top]>=h;top--)
24             if(stack[top]==h) ans--;
25         stack[++top]=h;
26     }
27     printf("%d\n",ans);
28     return 0;
29 }

 

posted @ 2017-08-18 19:22  Aptal丶  阅读(145)  评论(0编辑  收藏  举报