您的位置:首页 > 其它

Bzoj1113:[Poi2008]海报PLA:贪心+单调栈

2016-04-08 10:32 183 查看
题目链接:1113:[Poi2008]海报PLA

发现只要有一个向上凸起的矩形,就会ans++

所以用一发单调栈维护高度值,宽度并没有什么卵用

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=1000010;
int n,m,sta[maxn],a[maxn],ans=0;
int main(){
scanf("%d",&n); int top=0;
for (int i=1;i<=n;++i){
int x,y; scanf("%d%d",&x,&y);
while (top&&y<=sta[top])
{if (y<sta[top])ans++; top--;}
sta[++top]=y;
}
ans+=top; printf("%d",ans);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  BZOJ OI 贪心 单调栈