hdu 1506 Largest Rectangle in a Histogram 构造
题目链接:HDU - 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.
the largest rectangle in the specified histogram. Remember that this rectangle
must be aligned at the common base line.
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define inf 0x7fffffff
using namespace std;
typedef long long LL;
const int maxn=+; int n;
int l[maxn],r[maxn],an[maxn]; int main()
{
while (scanf("%d",&n)!=EOF && n)
{
for (int i= ;i<=n ;i++) {scanf("%d",&an[i]);l[i]=r[i]=i;}
an[]=an[n+]=-;
l[]=l[n+]=r[]=r[n+]=;
for (int i= ;i<=n ;i++)
{
while (an[l[i]- ]>=an[i])
l[i]=l[l[i]- ];
}
for (int i=n ;i>= ;i--)
{
while (an[r[i]+ ]>=an[i])
r[i]=r[r[i]+ ];
}
LL ans=;
for (int i= ;i<=n ;i++)
{
LL area=(LL)(r[i]-l[i]+)*(LL)an[i];
if (area>ans) ans=area;
}
printf("%I64d\n",ans);
}
return ;
}
hdu 1506 Largest Rectangle in a Histogram 构造的更多相关文章
- HDU 1506 Largest Rectangle in a Histogram (dp左右处理边界的矩形问题)
E - Largest Rectangle in a Histogram Time Limit:1000MS Memory Limit:32768KB 64bit IO Format: ...
- HDU 1506 Largest Rectangle in a Histogram set+二分
Largest Rectangle in a Histogram Problem Description: A histogram is a polygon composed of a sequenc ...
- HDU 1506 Largest Rectangle in a Histogram(区间DP)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1506 题目: Largest Rectangle in a Histogram Time Limit: ...
- DP专题训练之HDU 1506 Largest Rectangle in a Histogram
Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base l ...
- Hdu 1506 Largest Rectangle in a Histogram 分类: Brush Mode 2014-10-28 19:16 93人阅读 评论(0) 收藏
Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- hdu 1506 Largest Rectangle in a Histogram(单调栈)
L ...
- HDU 1506 Largest Rectangle in a Histogram(DP)
Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU -1506 Largest Rectangle in a Histogram&&51nod 1158 全是1的最大子矩阵 (单调栈)
单调栈和队列讲解:传送门 HDU -1506题意: 就是给你一些矩形的高度,让你统计由这些矩形构成的那个矩形面积最大 如上图所示,如果题目给出的全部是递增的,那么就可以用贪心来解决 从左向右依次让每一 ...
- hdu 1506 Largest Rectangle in a Histogram——笛卡尔树
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1506 关于笛卡尔树的构建:https://www.cnblogs.com/reverymoon/p/952 ...
随机推荐
- go语言的学习网站
1)http://www.runoob.com/go/go-data-types.html 2)https://github.com/Unknwon/the-way-to-go_ZH_CN/blob/ ...
- python中的re模块,常用函数介绍
参考: http://www.cnblogs.com/tina-python/p/5508402.htm ======== 1,预定义字符集,可以写在字符集[....]中 \d 数字: \D 非数字 ...
- Rational Rose 使用技巧
1.浏览区 2.菜单项 其中Format选项中: 决定各项是否显示,也可以通过右击-option选择 3.常用快捷键: F1:任何时候都可以按F1获得相关帮助,把鼠标放在某条菜单上按F1可以获得这条菜 ...
- git 上传项目到仓库
git 上传项目到仓库 第一步:建立仓库! 1.create new repository! 创建时最好选择 init (Initialize this repository with a READM ...
- 路由器配置PPP协议 CHAP验证 PAP验证
路由器配置PPP协议 CHAP验证 PAP验证 来源 https://www.cnblogs.com/tcheng/p/5967485.html PAP是两次握手,明文传输用户密码进行认证:CHAP是 ...
- 关于ECDSA/ECC(密钥加密传输)和ECDSA/ECDH(密钥磋商)
关于ECDSA/ECC(密钥加密传输)和ECDSA/ECDH(密钥磋商) 来源: https://blog.csdn.net/xueyepiaoling/article/details/6243337 ...
- freebsd网卡驱动程序详解
freebsd网卡驱动程序详解 来源 https://blog.csdn.net/h_cszc/article/details/7776116 /* 注释:xie_minix */ /*此处为BSD申 ...
- java equals 与 hashCode
转:http://m.blog.csdn.net/blog/pengchua/2297547# 如果你为某个类写了equals方法,那么应该同时编写hashCode方法.如果没有提供hashcode方 ...
- RSA解密报错java.security.spec.InvalidKeySpecException的解决办法
java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: IOException : algid p ...
- SSH整合一
Spring整合Hibernate 1.引入我们所需的jar包 2.在applicationContext.xml中植入我们的数据源和sessionFactory工厂,将生成权交由Spring容器进行 ...