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);
}
发现只要有一个向上凸起的矩形,就会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);
}
相关文章推荐
- 浅谈单调队列、单调栈
- WHOIS类的修改版
- 1.一些 贪心算法 的简单思维题:
- 贪心算法——字典序最小问题
- 贪心算法——区间调度问题
- 用单调栈解决最大连续矩形面积问题
- Jump Game I,II 贪心
- Wildcard Matching
- 贪心法实现无向图的划分 代码
- 贪心题目循环和控制台折行
- HDOJ 1009
- BZOJ3275 Number (最小割)
- 【解题报告】【USACO】酸奶工厂
- 【解题报告】【】交谊舞
- POJ 1328
- Best Cow Line
- HDU 1009 Fatmouse's Trade
- Begins and tests
- USACO2013 Nov. Gold T3,一道集合DP
- 数学-素数筛及其拓展