您的位置:首页 > 其它

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

2017-08-18 19:22 253 查看

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-可以省略的个数

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

#include <algorithm>
#include <cstdio>

using namespace std;

const int N(252333);
int stack
,top,ans;

inline void read(int &x)
{
x=0; int ch=getchar();
for(;ch>'9'||ch<'0';) ch=getchar();
for(;ch>='0'&&ch<='9';ch=getchar()) x=ch-'0'+x*10;
}

int main()
{
int n,w,h; read(n);
ans=n;
for(int i=1;i<=n;i++)
{
read(w),read(h);
for(;top>0&&stack[top]>=h;top--)
if(stack[top]==h) ans--;
stack[++top]=h;
}
printf("%d\n",ans);
return 0;
}

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: