Poj 2559 最大矩形面积 v单调栈
2014-11-13 20:48
453 查看
#include<iostream> #include<stack> #include<stdio.h> using namespace std; struct node { __int64 num,pre,next; }; int main() { int n; freopen("in.txt","r",stdin); while(scanf("%d",&n)>0&&n) { stack<node>Q; node tmp; __int64 ans=0,sum=0,num; scanf("%I64d",&tmp.num); tmp.pre=1; tmp.next=1; Q.push(tmp); for(int i=1;i<n;i++) { scanf("%I64d",&tmp.num); tmp.pre = tmp.next = 1; while(!Q.empty()&&tmp.num<=Q.top().num) { node tmp1=Q.top(); Q.pop(); ans=tmp1.num*(tmp1.pre+tmp1.next-1); if(!Q.empty()) Q.top().next+=tmp1.next; tmp.pre+=tmp1.pre; if(ans>sum) sum=ans; } Q.push(tmp); } while(!Q.empty()) { node tmp1=Q.top(); Q.pop(); if(!Q.empty()) Q.top().next+=tmp1.next; ans=tmp1.num*(tmp1.pre+tmp1.next-1); if(ans>sum) sum=ans; } printf("%I64d\n",sum); } return 0; }实在放心不下这个单调栈,还是把他存到自己博客里面吧
相关文章推荐
- POJ 2559 题解 最大矩形面积 单调栈
- Poj 2559 最大矩形面积 v单调栈 分类: Brush Mode 2014-11-13 20:48 81人阅读 评论(0) 收藏
- poj 2559 Largest Rectangle in a Histogram 求面积最大的矩形(单调栈)
- poj2559(单调栈)最大矩形面积
- 单调栈:柱形统计图中最大面积(POJ 2559)
- poj 2559 求连续的最大矩形面积(也可用于ccf最大连续矩形面积)
- Poj 2559 最大矩形面积
- POJ 2559 Largest Rectangle in a Histogram(单调栈维护最大矩形面积)
- Poj 2559 Largest Rectangle in a Histogram(柱形统计图中的最大矩形面积)
- Poj 2559 最大矩形面积
- POJ 2559 最大矩形面积 poj 3494
- POJ 2559最大矩形面积
- 连续区域最大矩形面积 POJ 1964 2082 2559 2796 3250 3494
- Get Many Persimmon Trees poj(动态规划 矩形面积一定时所圈中最大的树)
- poj2082 连续矩形最大面积
- poj2599 单调栈维护最大连续矩形面积
- poj3494 连续区域最大矩形面积 我要做的足够 强大
- 求全1的最大正方形的边长 和 全1的最大子矩阵的面积 和POJ 2559 最大直方图
- poj 2559求柱形图中最大矩形
- 计算最大矩形面积,POJ(2082)