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 ...
随机推荐
- Python学习-前台开发-ajax操作
概述 对于WEB应用程序:用户浏览器发送请求,服务器接收并处理请求,然后返回结果,往往返回就是字符串(HTML),浏览器将字符串(HTML)渲染并显示浏览器上. 1.传统的Web应用 一个简单操作需要 ...
- Python 黑魔法(持续收录)
Python 黑魔法(持续收录) zip 对矩阵进行转置 a = [[1, 2, 3], [4, 5, 6]] print(list(map(list, zip(*a)))) zip 反转字典 a = ...
- TensorFlow——深度学习笔记
深度学习与传统机器学习的区别 传统机器学习输入的特征为人工提取的特征,例如人的身高.体重等,深度学习则不然,它接收的是基础特征,例如图片像素等,通过多层复杂特征提取获得. 深度学习.人工智能.机器学习 ...
- maven学习(十八)——用Nexus搭建Maven私服
一.搭建nexus私服的目的 为什么要搭建nexus私服,原因很简单,有些公司都不提供外网给项目组人员,因此就不能使用maven访问远程的仓库地址,所以很有必要在局域网里找一台有外网权限的机器,搭建n ...
- 【bzoj3866】The Romantic Hero dp
题目描述 给你n个数,从中选出两个不相交非空集合S和T,使得S中的每一个元素都在T集合的前面,并且S集合中的所有数的亦或等于T集合中的所有数的与,求方案数 mod 10^9+7. 输入 The fir ...
- Snakes and Ladders LightOJ - 1151( 概率dp+高斯消元)
Snakes and Ladders LightOJ - 1151 题意: 有100个格子,从1开始走,每次抛骰子走1~6,若抛出的点数导致走出了100以外,则重新抛一次.有n个格子会单向传送到其他格 ...
- win7用户账户自动登录方法
为了计算机安全,相信使用Windows7系统的朋友大多都为自己的用户账户设置了或简单或复杂的密码,其实对于个人电脑来说,开机登录输入密码有时候会显得累赘,毕竟用户账户密码不仅仅是为了防止他人登录. 那 ...
- SHH框架的搭建
建立一个Web项目,然后导入如下包 l struts2包:在struts2-blank.war下的lib目录下,以及struts-2.3.15.1\lib下的struts和spring整合的插件包s ...
- webdriver操作iframe标记的编辑器
1.iFrame有ID 或者 name的情况//进入id="frame1"的frame中,定位id="div1"的div和id="input1&quo ...
- [ CodeVS冲杯之路 ] P3143
不充钱,你怎么AC? 题目:http://codevs.cn/problem/3143/ 大水题一道,只要会遍历,这里讲一下思路 先序遍历:先输出,然后左儿子,最后右儿子 中序遍历:先左儿子,再输出 ...