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的更多相关文章

  1. 【题解】hdu1506 Largest Rectangle in a Histogram

    目录 题目 思路 \(Code\) 题目 Largest Rectangle in a Histogram 思路 单调栈. 不知道怎么描述所以用样例讲一下. 7 2 1 4 5 1 3 3 最大矩形的 ...

  2. 【LeetCode】84. Largest Rectangle in Histogram

    Largest Rectangle in Histogram Given n non-negative integers representing the histogram's bar height ...

  3. 【LeetCode】084. Largest Rectangle in Histogram

    题目: Given n non-negative integers representing the histogram's bar height where the width of each ba ...

  4. 【LeetCode】84. Largest Rectangle in Histogram——直方图最大面积

    Given n non-negative integers representing the histogram's bar height where the width of each bar is ...

  5. 【Lintcode】122.Largest Rectangle in Histogram

    题目: Given n non-negative integers representing the histogram's bar height where the width of each ba ...

  6. 【LeetCode】84. Largest Rectangle in Histogram 柱状图中最大的矩形(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 单调栈 日期 题目地址: https://leetc ...

  7. HDU 1506 Largest Rectangle in a Histogram set+二分

    Largest Rectangle in a Histogram Problem Description: A histogram is a polygon composed of a sequenc ...

  8. HDU 1506 Largest Rectangle in a Histogram (dp左右处理边界的矩形问题)

    E - Largest Rectangle in a Histogram Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format: ...

  9. 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 ...

随机推荐

  1. struts2原理架构图

    struts2 原理架构图

  2. slidingmenu+fragment实现经常使用的側滑效果(包含Fragment状态的保存)

    一.需求 关于fragment的问题,一直想写一篇博客了.应该当初自己也是对这玩意一点都不熟悉到如今也大概知道个日常的使用的地步. 一个側滑的导航栏,内有4个条目.每个选项点击进入相应的界面,每个界面 ...

  3. [Angular 2] Inject Service

    TypeScript is used heavily as we build up our application, but TypeScript isn’t required. If you wan ...

  4. 基于redis 内存数据库简单使用

    在ecplise中使用内存数据的客端户,前提要准备要下载两个jar包 commons-pool2-2.0.jar jedis-2.4.2.jar 前提准备做好了,那我们就开启redis的服务,打开一个 ...

  5. 通过扩展RandomAccessFile类使之具备Buffer改善I/O性能--转载

    主体: 目前最流行的J2SDK版本是1.3系列.使用该版本的开发人员需文件随机存取,就得使用RandomAccessFile类.其I/O性能较之其它常用开发语言的同类性能差距甚远,严重影响程序的运行效 ...

  6. Linux下有线无线网络配置------命令模式

    1. 列出启用网络设备的所有信息: ifconfig 2. 将网络设备设置为启用或者不启用 不启用设备eth0 ifconfig eth0 down 启用设备eth0: Will bring eth0 ...

  7. git 创建远程仓库

    在远程服务器上$ cd /server/path/ $ git init --bare myproject.git 在本地 1> $ cd /client/path/ 运行 git init 2 ...

  8. SPOJ 181 - Scuba diver 二维背包

    潜水员要潜水,给出n个气缸(1<=n<=1000),每个气缸中有氧气量为ti,氮气量为ai,气缸重量为wi(1<=ti<=21,1<=ai<=79,1<=wi ...

  9. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

  10. 初识html、css时随笔记录

    css部分样式 圆框效果:border-radius:5px; 固定样式:position:fixed;悬浮窗在IE6中position:absolute其余浏览器可以用fixed: 使table中的 ...