uva 1506 Largest Rectangle in a Histogram
Largest Rectangle in a Histogram
http://acm.hdu.edu.cn/showproblem.php?pid=1506
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
rectangles aligned at a common base line. The rectangles have equal widths but
may have different heights. For example, the figure on the left shows the
histogram that consists of rectangles with the heights 2, 1, 4, 5, 1, 3, 3,
measured in units where 1 is the width of the rectangles:

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.
describes a histogram and starts with an integer n, denoting the number of
rectangles it is composed of. You may assume that 1 <= n <= 100000. Then
follow n integers h1, ..., hn, where 0 <= hi <= 1000000000. These numbers
denote the heights of the rectangles of the histogram in left-to-right order.
The width of each rectangle is 1. A zero follows the input for the last test
case.
the largest rectangle in the specified histogram. Remember that this rectangle
must be aligned at the common base line.
考虑对于第i个数,求出当这个数成为最小值时,往左往右分别最远能到哪里。
使用单调队列来实现这一过程。
#include<cstdio>
#include<algorithm>
#define N 100001 #ifdef WIN32
#define ll "%I64d\n"
#else
#define ll "%lld\n"
#endif using namespace std;
int n,a[N],b[N];
int q[N],tmp[N],head,tail;
int l[N],r[N];
long long ans;
void monotonous(int *c,int *d)
{
q[]=c[]; tmp[]=;
head=; tail=;
for(int i=;i<=n;i++)
{
if(c[i]<q[tail-])
while(head<tail && q[tail-]>c[i]) d[tmp[--tail]]=i-;
q[tail]=c[i];
tmp[tail++]=i;
}
while(head<tail) d[tmp[head++]]=n;
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
if(!n) return ;
ans=;
for(int i=;i<=n;i++) scanf("%d",&a[i]),b[n-i+]=a[i];
monotonous(a,r);
monotonous(b,l);
for(int i=;i<=n;i++) tmp[i]=l[i];
for(int i=;i<=n;i++) l[n-i+]=n-tmp[i]+;
for(int i=;i<=n;i++) ans=max(ans,1ll*(r[i]-l[i]+)*a[i]);
printf(ll,ans);
}
}
uva 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 构造
题目链接:HDU - 1506 A histogram is a polygon composed of a sequence of rectangles aligned at a common ba ...
- 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 ...
- 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 ...
- HUD 1506 Largest Rectangle in a Histogram
Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
随机推荐
- wamp下安装https 实现 ssl 协议,主要是编写小程序通讯
也不知道腾讯为啥要这个限制,是想卖他的服务器资源么 简单几句话 1 wamp3.0.X的版本不行,我折腾了一天半,放弃了,换成wamp2.5 一次通过 2 证书 去腾讯云申请,单独域名的可以申请免费的 ...
- 王者荣耀交流协会beta冲刺贡献分分配结果
根据原来约定的(贡献分分配规则){http://www.cnblogs.com/gaoyb348/p/7828523.html} 总共20个任务,一共35分,那么一个任务1.75分. 冉华完成了9个任 ...
- Thinkphp5图片、音频和视频文件上传
首先是同步上传,最为基础的上传的方式,点击表单提交之后跳转那种.如下前端代码 <!DOCTYPE html> <html lang="en"> <he ...
- 命名空间(namespace)// 友元函数
17.2.命名空间 命名空间(namespace)为防止名字冲突提供了更加可控的机制.命名空间能够划分全局命名空间,这样使用独立开发的库更加容易了.一个命名空间就是一个作用域,通过在命名空间内部定义库 ...
- 数据库时间内接受的是lang类型的时间 分为三种字段 第一种只存日期 第二种存日期+时间 第三种时间戳
数据库时间内接受的是lang类型的时间 分为三种字段 第一种只存日期 第二种存日期+时间 第三种时间戳
- hdu2295-Radar
有n个城市,\(m\)个雷达,\(k\)个操作员,每个操作员只能操作一个雷达.每个雷达的覆盖范围是一个以雷达坐标为中心的圆,所有雷达的覆盖半径是相同的. 现在给出这\(n\)个城市,\(m\)个雷达的 ...
- [洛谷P3332][ZJOI2013]K大数查询
题目大意:有$n$个位置,$m$个操作.操作有两种: $1\;l\;r\;x:$在区间$[l,r]$每个位置加上一个数$x$ $2\;l\;r\;k:$询问$[l,r]$中第$k$大的数是多少. 题解 ...
- [Leetcode] jump game ii 跳跃游戏
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- HDOJ.2084 数塔(DP)
数塔 点我挑战题目 题意分析 DP的思想,自上而下计算. [这几天比较忙 有空补上] 代码总览 /* Title:HDOJ.2084 Author:pengwill Date:2017-1-14 */ ...
- float,absolute脱离文档流的总结
dom元素脱离文档流,有如下几种方式: 1. float 脱离文档流,其他dom元素无视他,在其下方布局,但是其未脱离文本流,其他元素的文本会认为他存在,环绕他布局.父元素会无视他,因此无法获取其高度 ...