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 ...
随机推荐
- unity灯光Lightmapping、LightProbes
1.为什么要用Lightmapping? 简单来说就是实时灯光计算十分耗时,随着光源越多,计算耗时会倍增.使用Lightmap模拟灯光带来的效果,便不用去计算灯光,会带来性能上的大大提升. 当然一个复 ...
- 【志银】Ubuntu Apache2配置SSL证书
1.准备工作 证书文件:zain.crt.zain.key /etc/apache2/文件夹下新建ssl 文件夹,将证书文件放入/etc/apache2/ssl 2.配置SSL证书 打开/etc/ap ...
- mysql语法结构
环境:win7 64位.mysql 适合阅读者:对sql基本语法有一定了解 <建表语句>: create table <表名>( <列名> <类型> & ...
- 用Linkedhashmap的LRU特性及SoftReference软引用构建二级缓存
LRU: least recently used(近期最少使用算法).LinkedHashMap构造函数可以指定其迭代顺序:LinkedHashMap(int initialCapacity, flo ...
- 软工实践 - 第十六次作业 Alpha 冲刺 (7/10)
队名:起床一起肝活队 组长博客:https://www.cnblogs.com/dawnduck/p/10013959.html 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过 ...
- SQL小助手——SQL Prompt
背景: 当数据库设计的比较复杂.庞大时,我们如果对脚本不是很熟悉,就会很难完成看似简单的增.删.改.查的操作.我们需要一款软件来给出相应的提示或帮助,来提高代码的可读性,更快更好的完成任务. 简介: ...
- LeetCode -- Product of Array Except Self My Submissions Question
Question: Given an array of n integers where n > 1, nums, return an array output such that output ...
- 关于Yarn源码那些事-前传之ResourceManager篇(一)初始化
在关于Yarn那些事的博客里,介绍的主要是针对任务提交的一个动态流程说明,而其中牵涉到的一些细节问题,必须通过Resourcemanager的启动和NodeManager的启动,来更好的说明. 而本系 ...
- 电阻 (resistance)
电阻 (resistance) 题目描述 每次小x物理作业没做完时,总是会去和老师交流感情,他们之间由此建立起来良好的师生关系.于是有一天,老师带着一道物理难题来见小x. 这道题给出了一个有n个电阻的 ...
- 昨天用到的一个sql查询。可取处,用max
SELECT T_AssetInfos_ID, MAX(T_AssetConstruct_Name), MAX(T_AssetProperties_Name), SUM(CAST(PropertyVa ...