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

时间:2023-03-09 02:05:03
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
BZOJ——T 1113: [Poi2008]海报PLA

Sample Output

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

HINT

Source

宽度并没有什么用。。。

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

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

 #include <algorithm>
#include <cstdio> using namespace std; const int N();
int stack[N],top,ans; inline void read(int &x)
{
x=; int ch=getchar();
for(;ch>''||ch<'';) ch=getchar();
for(;ch>=''&&ch<='';ch=getchar()) x=ch-''+x*;
} int main()
{
int n,w,h; read(n);
ans=n;
for(int i=;i<=n;i++)
{
read(w),read(h);
for(;top>&&stack[top]>=h;top--)
if(stack[top]==h) ans--;
stack[++top]=h;
}
printf("%d\n",ans);
return ;
}