【HDOJ】1506 Largest Rectangle in a Histogram
Twitter还是Amazon拿这个题目当过面试题。DP区间求面积。
/* 1506 */
#include <cstdio>
#include <cstring>
#include <cstdlib> #define MAXN 100005
#define INF 999999 int l[MAXN], r[MAXN];
__int64 a[MAXN]; __int64 max(__int64 a, __int64 b) {
return a>b ? a:b;
} int main() {
int n;
int i, j, k;
__int64 ans; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif while (scanf("%d",&n)!=EOF && n) {
for (i=; i<=n; ++i)
scanf("%I64d", &a[i]);
a[] = a[n+] = -INF;
l[] = ;
for (i=; i<=n; ++i) {
if (a[i-] < a[i]) {
l[i] = i;
} else {
j = i;
while (j--) {
if (a[j] < a[i]) {
l[i] = j+;
break;
} else {
j = l[j];
}
}
}
}
r[n+] = n+;
for (i=n; i>; --i) {
if (a[i+] < a[i]) {
r[i] = i;
} else {
j = i;
while (j++ <= n) {
if (a[j] < a[i]) {
r[i] = j - ;
break;
} else {
j = r[j];
}
}
}
} ans = -INF;
for (i=; i<=n; ++i) {
ans = max(ans, a[i]*(r[i]-l[i]+));
}
printf("%I64d\n", ans);
} return ;
}
【HDOJ】1506 Largest Rectangle in a Histogram的更多相关文章
- 【题解】hdu1506 Largest Rectangle in a Histogram
目录 题目 思路 \(Code\) 题目 Largest Rectangle in a Histogram 思路 单调栈. 不知道怎么描述所以用样例讲一下. 7 2 1 4 5 1 3 3 最大矩形的 ...
- 【LeetCode】84. Largest Rectangle in Histogram
Largest Rectangle in Histogram Given n non-negative integers representing the histogram's bar height ...
- 【LeetCode】084. Largest Rectangle in Histogram
题目: Given n non-negative integers representing the histogram's bar height where the width of each ba ...
- 【LeetCode】84. Largest Rectangle in Histogram——直方图最大面积
Given n non-negative integers representing the histogram's bar height where the width of each bar is ...
- 【Lintcode】122.Largest Rectangle in Histogram
题目: Given n non-negative integers representing the histogram's bar height where the width of each ba ...
- 【LeetCode】84. Largest Rectangle in Histogram 柱状图中最大的矩形(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 单调栈 日期 题目地址: https://leetc ...
- 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左右处理边界的矩形问题)
E - Largest Rectangle in a Histogram Time Limit:1000MS Memory Limit:32768KB 64bit IO Format: ...
- 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 ...
随机推荐
- cocos2d-x项目过程记录(ios和android设备的适配)
(原创作品,欢迎转载,注明出处,谢谢:http://www.cnblogs.com/binxindoudou/admin/EditPosts.aspx?postid=3213645) 1.原理分析的博 ...
- [转] openjdk和jdk的区别与联系
使用过LINUX的人都应该知道,在大多数LINUX发行版本里,内置或者通过软件源安装JDK的话,都是安装的openjdk,那么到底什么是openjdk,它与sun jdk有什么关系和区别呢? 历史上的 ...
- ubuntu12.10中没有/etc/inittab文件探究
1. 我们首先来看一下Linux系统开机启动过程: Ubuntu是Linux系统的衍生系统,其开机启动过程与上图相差不大,但是随着系统的不断发展,终究还是有不同的地方,下面,我们来了解一下Ubuntu ...
- IP 转地址
1.需要 QQWry.Dat IP 地址数据库 2辅助类库 using System; using System.Collections.Generic; using System.IO; usin ...
- asp.net微信开发第五篇----用户分组管理
上一篇已讲解到新建用户分组,移动用户到分组的功能,这一章主要讲解修改分组名称和删除分组 开发者可以使用接口,对公众平台的分组进行查询.创建.修改.删除等操作,也可以使用接口在需要时移动用户到某个分组. ...
- (转)php中__autoload()方法详解
转之--http://www.php100.com/html/php/lei/2013/0905/5267.html PHP在魔术函数__autoload()方法出现以前,如果你要在一个程序文件中实例 ...
- How do I size a UITextView to its content?
UITextView 自适应高度,搬来一篇stack上的: Is there a good way to adjust the size of a UITextView to conform to ...
- NSString截取字符串
NSString 是经常会用到的,很多时候需要对字符串进行一些处理,本文简单介绍字符串截取操作: 比如: 1.定义一个字符串a, 截取a的某一个部分(子串) NSString *a = @" ...
- cocoapods安装失败
ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the ...
- Linux网络配置命令ifconfig输出信息解析
eth0 Link encap:Ethernet HWaddr 00:1e:4f:e9:c2:84 inet addr:128.224.163.153 Bcast:128.224.163 ...