HUD 1506 Largest Rectangle in a Histogram
Largest Rectangle in a Histogram
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 19580 Accepted Submission(s): 5921
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.
4 1000 1000 1000 1000
0
4000
#include<cstdio>
#include<algorithm>
using namespace std;
#define LL long long
const int maxn= ;
#ifdef WIN32
#define lld "I64d"
#else
#define lld "lld"
#endif int a[maxn],b[maxn];
int l[maxn],r[maxn],tmp[maxn],q[maxn];
int n,m;
void work(int c[] ,int d[]) {
q[]=c[]; tmp[]=;
int head=,tail=;
for(int i=;i<=n;++i) {
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)&&n!=) {
LL ans=;
for(int i=;i<=n;++i)
scanf("%d",a+i),b[n-i+]=a[i];
work(a,r);
work(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*a[i]*(r[i]-l[i]+));
printf("%lld\n",ans);
}
return ;
}
HUD 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 ...
- uva 1506 Largest Rectangle in a Histogram
Largest Rectangle in a Histogram http://acm.hdu.edu.cn/showproblem.php?pid=1506 Time Limit: 2000/100 ...
- 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 ...
随机推荐
- JdbcTemplate类对sql的操作使用
<!--方式一: dbcp 数据源配置,在测试环境使用单连接 --> <bean id="dataSource" class="org.apache.c ...
- MFC编辑框换行
字符串结尾加上"\r\n": 编辑框属性设置:Auto HScroll为False,Multiline为True,Want Return为True. =============== ...
- (17)zabbix自定义用户key与参数User parameters
为什么要自定义KEY 有时候我们想让被监控端执行一个zabbix没有预定义的检测,zabbix的用户自定义参数功能提供了这个方法. 我们可以在客户端配置文件zabbix_angentd.conf里面配 ...
- GIMP如何创建layer masks,创建,删除,禁用,复制mask
这次案例是背景替换,采用创建一个新的layer masks: 前期准备好要处理的图片: 1.创建一个新的图层,选择Layer,点击Mask,选择Add Layer Mask: 根据情况选择合适 ...
- 如何用纯 CSS 创作阶梯文字特效
效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/MXYBEM 可交互视频教 ...
- LeetCode(107) Binary Tree Level Order Traversal II
题目 Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from l ...
- 基于顺序链表的栈的顺序存储的C风格实现
头文件: #ifndef _SEQSTACK_H_ #define _SEQSTACK_H_ typedef void SeqStack; //创建一个栈 SeqStack* SeqStack_Cre ...
- mysqldump 常见报错及解决
mysqldump失败案例及解决: 1.mysqldump: Error 2020: Got packet bigger than 'max_allowed_packet' bytes when du ...
- suse-12-linux gcc gcc-c++离线安装教程,不使用yum等
最近这几天接手新的项目,要部署新的服务器,采用目前比较主流的框架开发的程序,前后端进行了分离.在这种情况下就需要使用nginx做代理,以便于很好的区分前后端,目前虽然已经有很多很好的发布体系,但是个人 ...
- 【Luogu】P1155双栈排序(二分图)
题目链接在此 此题一开始写了个深搜,过了30%的数据,也就是n<=10的那一段.... 然后看了题解发现这是个二分图的判断. 我们先举例子找到不能放进一个栈里的规律.设有数列[2,3,1,4] ...