hdoj - 1506 直方图中最大的矩形

Usually, histograms are used to represent discrete distributions, e.g., the frequencies of characters in texts. Note that the order of the rectangles, i.e., their heights, is important. Calculate the area of the largest rectangle in a histogram that is aligned at the common base line, too. The figure on the right shows the largest aligned rectangle for the depicted histogram.
4 1000 1000 1000 1000
0
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm> using namespace std; int a[];
int l[],r[];
int main()
{
int n; while(scanf("%d",&n) && n != )
{
long long ans=;
memset(a,,sizeof(a));
for(int i = ;i<n;i++)
{
scanf("%d",&a[i]);
l[i] = r[i] = i;
while(l[i] > && a[l[i]-] >= a[i])
{
l[i] = l[l[i]-];
}
}
for(int i = n-;i>=;i--)
{
while(r[i]<n- && a[r[i]+] >= a[i])
{
r[i] = r[r[i]+];
}
}
for(int i = ;i<n;i++)
{
long long s = (long long)a[i]*(r[i]-l[i]+);
if(s>ans)
{
ans = s;
}
}
printf("%lld\n",ans);
}
return ;
}
Largest Rectangle in a Histogram【暑期培训Q题】【DP】【递归】
hdoj - 1506 直方图中最大的矩形的更多相关文章
- [LeetCode] Largest Rectangle in Histogram 直方图中最大的矩形
Given n non-negative integers representing the histogram's bar height where the width of each bar is ...
- hdu1506 直方图中最大的矩形 单调栈入门
hdu1506 直方图中最大的矩形 单调栈入门 直方图是由在公共基线对齐的矩形序列组成的多边形.矩形具有相同的宽度,但可能具有不同的高度.例如,左侧的数字显示了由高度为2,1,4,5,1,3,3的矩形 ...
- [LeetCode] 84. Largest Rectangle in Histogram 直方图中最大的矩形
Given n non-negative integers representing the histogram's bar height where the width of each bar is ...
- AcWing:131. 直方图中最大的矩形(贪心 + 单调栈)
直方图是由在公共基线处对齐的一系列矩形组成的多边形. 矩形具有相等的宽度,但可以具有不同的高度. 例如,图例左侧显示了由高度为2,1,4,5,1,3,3的矩形组成的直方图,矩形的宽度都为1: 通常,直 ...
- [leetcode]84. Largest Rectangle in Histogram直方图中的最大矩形
Given n non-negative integers representing the histogram's bar height where the width of each bar is ...
- 如何在html中做圆角矩形和 只有右边的"分隔线"
这个网站满好的,可以常看看 css-matic中有几个很好的写css可视化的工具 其实做css 版式布局等都可以有工具的 推荐40个优秀的免费CSS工具 debugger正则表达式在线 其实是对(理论 ...
- CODESOFT中的圆角矩形的弧度该怎样设置?
CODESOFT标签设计软件提供多种图形制作按钮,方便用户更为快捷的制作标签.其中就包括矩形,圆角矩形的快捷创建按钮.本文将介绍如何设置CODESOFT圆角矩形的弧度. 若有疑问可直接访问:htt ...
- hdoj 1506&&1505(City Game) dp
// l表示从l[i]到i连续大于a[i]的最远左区间.r表示从i到r[i]连续大于a[i]的最远又区间 DP 找出 a[i] 的最远左区间和最远右区间与自己连着的比自己大的数的长度 , 然后用这个长 ...
- SQL Server 中统计信息直方图中对于没有覆盖到谓词预估以及预估策略的变化(SQL2012-->SQL2014-->SQL2016)
本位出处:http://www.cnblogs.com/wy123/p/6770258.html 统计信息写过几篇了相关的文章了,感觉还是不过瘾,关于统计信息的问题,最近又踩坑了,该问题虽然不算很常见 ...
随机推荐
- MySQLNonTransientConnectionException: Could not create connection to database server.
MySQLNonTransientConnectionException: Could not create connection to database server. Spring整合mybati ...
- 【面试突击】-Redis常见面试题(二)
1.什么是Redis?简述它的优缺点? Redis本质上是一个Key-Value类型的内存数据库,很像memcached,整个数据库统统加载在内存当中进行操作,定期通过异步操作把数据库数据flush到 ...
- Hybris订单价格的折扣维护
backoffice里创建一个新订单,维护一个行项目,添加一个产品: 在行项目的SubTotal界面,维护Base Price,在Discount values字段里,输入折扣信息:discount: ...
- 【兼容调试】cffi library '_openssl' has no function, constant or global variable named 'Cryptography_HAS
重装cryptography就好了. conda uninstall cryptography conda install cryptography https://github.com/pyca/c ...
- java web添加spring jar 包
maven依赖: <properties> <spring.version>5.1.7.RELEASE</spring.version> </properti ...
- github hooks 配置教程 钩子搭建(实测通过,手把手教程)
tips:如果本文对你有用,请爱心点个赞,提高排名,让这篇文章帮助更多的人.谢谢大家!❤ 本人hooks搭建成功,全程参考JellyBool老师的视频教程,有不懂的可以先去看下这个视频,跟着操作.本文 ...
- MavenWrapper替代Maven
1. 说明 jdk8已经安装成功 Maven已经安装成功 参见Maven Wrapper 2. Maven初始化项目 注:初次执行,Maven会下载很多jar,需等待几分钟 mvn archetype ...
- django数据表生成
在创建的app中models.py生成表结构 class 表名(models.Model): #表名一般首字母大写 中突出信息的大写 列名=models.Charfield(max_lenth=) # ...
- android studio中为gradle指定cmake版本
Android Studio相当于是Intellij基础上写了一个AS插件,这个插件使用gradle作为构建系统,因此构建出现问题先考虑gradle的文档. gradle可以使用native buil ...
- Linux指令(文件目录类)
pwd 显示当前工作目录的绝对路径 ls [选项] [目录或是文件] 常用选项 -a 显示当前目录所有的文件和目录,包括隐藏的 -l 以列表的方式显示信息 cd [参数] (功能描述:切换到指定目录) ...