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 ...
随机推荐
- 动态规划——最长上升子序列LIS及模板
LIS定义 一个数的序列bi,当b1 < b2 < … < bS的时候,我们称这个序列是上升的.对于给定的一个序列(a1, a2, …, aN),我们可以得到一些上升的子序列(ai1 ...
- Scrum1
Scrum1 组员 任务分工 贡献 林泽宇 团队分工.撰写博客.修改完善需求规格说明书.整理代码规范 李涵 后端架构设计 尹海川 logo设计修改.数据库数据 郏敏杰 课堂展示.查阅资料.整理关键和难 ...
- 针对“来用”团队项目之NABC分析
本项目特点之一:扩展性强 NABC分析: N(need):我们这个开发的这个软件主要是集娱乐软件和实用工具于一身的大容器,这里面有很多应用程序,针对不同用户需要,至少有一款应用程序能够满足用户的需要, ...
- TensorFlow源码框架 杂记
一.为什么我们需要使用线程池技术(ThreadPool) 线程:采用“即时创建,即时销毁”策略,即接受请求后,创建一个新的线程,执行任务,完毕后,线程退出: 线程池:应用软件启动后,立即创建一定数量的 ...
- DAY7敏捷冲刺
站立式会议 工作安排 (1)服务器配置 服务器端项目结构调整 (2)数据库配置 单词学习记录+用户信息 (3)客户端 客户端项目结构调整,代码功能分离 燃尽图 燃尽图有误,已重新修改,先贴卡片的界面, ...
- TCP系列12—重传—2、Linux超时重传引入示例
在前面我们概述了TCP的超时重传之后我们简单的看一下tcp超时重传的示例.首先简单的描述一下测试过程 1.设置/proc/sys/net/ipv4/tcp_early_retrans为2,关掉TLP功 ...
- 一个项目的Makefile编写及调试
父Makefile 在src目录下包含很多文件夹,那么需要遍历所有的目录执行Makefile,那么给一个在src目录下的Makefile. # 需要排除的目录 exclude_dirs := incl ...
- OSG配置捷径,VS2013+WIN10
在自己电脑上用CMAKE已经编译好了,上传到百度云里面了. 环境是WIN10+VS2013. 链接:http://pan.baidu.com/s/1hrO7GFE 密码:fwkw 解压之后放在C盘或者 ...
- 《学习OpenCV》课后习题解答4
题目:(P104) 练习使用感兴趣区域(ROI).创建一个210*210的单通道图像并将其归0.在图像中使用ROI和cvSet()建立一个增长如金字塔状的数组.也就是:外部边界为0,下一个内部边界应该 ...
- asp.net mvc4使用log4.net 日志功能
对于网站来讲,不能把异常信息显示给用户,异常信息只能记录到日志,出了问题把日志文件发给开发人员,就能知道问题所在. 下面演示网站 出错后自动添加出错日志的实例 (1)新建一个WebApplicatio ...