很显然是单调栈

这里记录一种新的写法,这种写法基于递推,但是相比之下比单调栈更好写

#include<cstdio>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<stack>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
//#define endl "\n"
#define inf 0x3f3f3f3f
#define me(a,b) memset(a,b,sizeof(a))
#define maxn 100000+5
long long n,a[maxn];
int l[maxn],r[maxn];
stack<long long> st;
long long mx;
void init()
{
mx=;
while(!st.empty())
st.pop();
}
int main()
{
while(cin>>n&&n){
init();
for(int i=;i<=n;i++)
scanf("%I64d",&a[i]),l[i]=r[i]=i;
a[]=;
for(int i=;i<=n;i++){
int now=i;
while(now>&&a[i]<=a[now-]) now=l[now-];
l[i]=now;
}
for(int i=n-;i;i--){
int now=i;
while(now<n&&a[i]<=a[now+]) now=r[now+];
r[i]=now;
}
for(int i=;i<=n;i++)
mx=max(mx,a[i]*(r[i]-l[i]+));
cout<<mx<<endl;
}
}

Largest Rectangle in a Histogram POJ - 2559的更多相关文章

  1. Largest Rectangle in a Histogram POJ - 2559 (单调栈)

    Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base l ...

  2. HDU——T 1506 Largest Rectangle in a Histogram|| POJ——T 2559 Largest Rectangle in a Histogram

    http://acm.hdu.edu.cn/showproblem.php?pid=1506  || http://poj.org/problem?id=2559 Time Limit: 2000/1 ...

  3. POJ 2559 Largest Rectangle in a Histogram -- 动态规划

    题目地址:http://poj.org/problem?id=2559 Description A histogram is a polygon composed of a sequence of r ...

  4. poj 2559 Largest Rectangle in a Histogram (单调栈)

    http://poj.org/problem?id=2559 Largest Rectangle in a Histogram Time Limit: 1000MS   Memory Limit: 6 ...

  5. [POJ 2559]Largest Rectangle in a Histogram 题解(单调栈)

    [POJ 2559]Largest Rectangle in a Histogram Description A histogram is a polygon composed of a sequen ...

  6. poj 2559 Largest Rectangle in a Histogram 栈

    // poj 2559 Largest Rectangle in a Histogram 栈 // // n个矩形排在一块,不同的高度,让你求最大的矩形的面积(矩形紧挨在一起) // // 这道题用的 ...

  7. stack(数组模拟) POJ 2559 Largest Rectangle in a Histogram

    题目传送门 /* 题意:宽度为1,高度不等,求最大矩形面积 stack(数组模拟):对于每个a[i]有L[i],R[i]坐标位置 表示a[L[i]] < a[i] < a[R[i]] 的极 ...

  8. poj 2559 Largest Rectangle in a Histogram - 单调栈

    Largest Rectangle in a Histogram Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19782 ...

  9. POJ 2559 Largest Rectangle in a Histogram(单调栈)

    传送门 Description A histogram is a polygon composed of a sequence of rectangles aligned at a common ba ...

随机推荐

  1. gulp 压缩文件2 摘

    一下代码用来简单的压缩 .js  和 .css   ;  在cmd里执行 gulp minifycss    minifyjs,各task执行是正常的. 注意,先安装后相应的模块,建议安装到本地. 说 ...

  2. [Effective Java 读书笔记] 第二章 创建和销毁对象 第六-七条

    第六条 消除过期引用 JAVA中依然会有 memory leak的,比如一个栈先增长再收缩,那么从栈中弹出的对象是不会被当做垃圾回收的,即时使用栈的程序不再引用这些对象.这是因为栈的内部维护着对这些对 ...

  3. jq根据table的tr行数动态删除相应的行

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. Linux 服务器注意事项

    1.创建时  数据文件一定分盘挂载 2.LVM 虚拟磁盘卷是否创建    有争议??? 3.hosts 文件 最好添加本机映射          主机名  127.0.0.1      4.iptab ...

  5. [Redis-CentOS7]Redis设置连接密码(九)

    设置Redis密码 修改/etc/redis.conf 一定要强密码redis为内存存储 抗暴力破解强 requirepass password 重启服务 systemctl restart redi ...

  6. 同步锁——ReentrantLock

    本博客系列是学习并发编程过程中的记录总结.由于文章比较多,写的时间也比较散,所以我整理了个目录贴(传送门),方便查阅. 并发编程系列博客传送门 Lock接口简介 在JUC包下面有一个java.util ...

  7. IT运维软件免费送 智和信通战疫活动火热进行中

    突如其来的“新型冠状病毒”疫情牵动了全国人民的心,这是一场与病毒抗争,为生命逆行与时间赛跑的战役.举国上下众志成城面对疫情,在线医疗.在线教学.在线办公.在线会议.电商销售成为热点.线上经济的火热给企 ...

  8. Pyinstaller打包exe,丢失图标等问题

    Pyinstaller打包exe,丢失图标等问题 一.原因 exe运行时会解压一个名为'_MEI*'的资源文件夹到电脑的临时目录,程序结束时删除. 程序里使用'\图标.png'这样的路径,exe运行时 ...

  9. jQuery--dataTable 前端分页与后端分页 及遇到的问题

    (1)区别 前端分页:一次性把所有数据全都放在前端,由前端进行处理:适合请求的数据量不大的情况 后端分页:服务器模式,所有的分页,搜索,排序等操作在服务器端完成,然后前端去请求数据:适合量大的情况 ( ...

  10. 盒模型大小取决于它的padding,margin,border数值

    盒模型规定了元素框处理元素内容width与height值.内边距padding.边框border 和 外边距margin 的数值大小.边框内的空白是内边距padding,边框外的空白是外边距margi ...