stack(数组模拟) POJ 2559 Largest Rectangle in a Histogram
/*
题意:宽度为1,高度不等,求最大矩形面积
stack(数组模拟):对于每个a[i]有L[i],R[i]坐标位置 表示a[L[i]] < a[i] < a[R[i]] 的极限情况
st[]里是严格单调递增,若不记录的话还要O(n)的去查找L,R,用栈的话降低复杂度
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <iostream>
using namespace std; typedef long long ll; const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f;
int a[MAXN], L[MAXN], R[MAXN];
int st[MAXN]; int main(void) //POJ 2559 Largest Rectangle in a Histogram
{
// freopen ("POJ_2559.in", "r", stdin); int n;
while (scanf ("%d", &n) == )
{
if (n == ) break;
for (int i=; i<=n; ++i) scanf ("%d", &a[i]);
memset (st, , sizeof (st)); int p = ;
for (int i=; i<=n; ++i)
{
while (p >= && a[st[p-]] >= a[i]) p--;
L[i] = (p == ) ? : st[p-];
st[p++] = i;
} p = ;
for (int i=n; i>=; --i)
{
while (p >= && a[st[p-]] >= a[i]) p--;
R[i] = (p == ) ? n + : st[p-];
st[p++] = i;
} ll ans = ;
for (int i=; i<=n; ++i)
{
ans = max (ans, (ll) a[i] * (R[i] - L[i] - ));
}
printf ("%I64d\n", ans);
} return ;
}
stack(数组模拟) POJ 2559 Largest Rectangle in a Histogram的更多相关文章
- [POJ 2559]Largest Rectangle in a Histogram 题解(单调栈)
[POJ 2559]Largest Rectangle in a Histogram Description A histogram is a polygon composed of a sequen ...
- poj 2559 Largest Rectangle in a Histogram 栈
// poj 2559 Largest Rectangle in a Histogram 栈 // // n个矩形排在一块,不同的高度,让你求最大的矩形的面积(矩形紧挨在一起) // // 这道题用的 ...
- poj 2559 Largest Rectangle in a Histogram (单调栈)
http://poj.org/problem?id=2559 Largest Rectangle in a Histogram Time Limit: 1000MS Memory Limit: 6 ...
- POJ 2559 Largest Rectangle in a Histogram -- 动态规划
题目地址:http://poj.org/problem?id=2559 Description A histogram is a polygon composed of a sequence of r ...
- POJ 2559 Largest Rectangle in a Histogram (单调栈或者dp)
Largest Rectangle in a Histogram Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15831 ...
- poj 2559 Largest Rectangle in a Histogram - 单调栈
Largest Rectangle in a Histogram Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19782 ...
- POJ 2559 Largest Rectangle in a Histogram(单调栈)
传送门 Description A histogram is a polygon composed of a sequence of rectangles aligned at a common ba ...
- 题解报告:poj 2559 Largest Rectangle in a Histogram(单调栈)
Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base l ...
- POJ 2559 Largest Rectangle in a Histogram
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18942 Accepted: 6083 Description A hi ...
随机推荐
- 【深度探索c++对象模型】Function语义学之成员函数调用方式
非静态成员函数 c++的设计准则之一就是:非静态成员函数至少和一般的非成员函数有相同的效率.编译器内部已将member函数实体转换为对等的nonmember函数实体. 转化步骤: 1.改写函数原型以安 ...
- CSS浮动通俗讲解
首先要知道,div是块级元素,在页面中独占一行,自上而下排列,也就是传说中的流.如下图: 可以看出,即使div1的宽度很小,页面中一行可以容下div1和div2,div2也不会排在div1后边,因为d ...
- pagePiling.js - 创建美丽的全屏滚动效果
在线演示 在线演示 本地下载 全屏滚动效果是近期很流行的网页设计形式,带给用户良好的视觉和交互体验. pagePiling.js 这款jQuery插件能够帮助前端开发者轻松实现这样的效果.支持全部的主 ...
- Hibernate之三态篇
一.概况 (一)瞬时状态(暂时态) 在对象中假设对象刚被创建但没有被持久化的话就是瞬时态 特点: (1) 不和 Session 实例关联 (2)在数据库中没有和瞬时对象关联的记录 (二)持久状态 持久 ...
- oracle官方文档_查看初始化參数(举例)
原创作品,出自 "深蓝的blog" 博客.深蓝的blog:http://blog.csdn.net/huangyanlong/article/details/46864217 记录 ...
- Effective C++学习笔记(Part Two:Item 5-12)
近期最终把effectvie C++细致的阅读了一边,非常惊叹C++的威力与魅力.近期会把近期的读书心得与读书笔记记于此.必备查找使用,假设总结有什么不当之处,欢迎批评指正: 如今仅仅列出框架. ...
- C# 敏感词过滤
public class BadWordFilter { #region 变量 private HashSet<string> hash = new HashSet<string&g ...
- 返回模式有流式(streaming)和整体(total) 热词词表解决方案
重要术语说明_语音识别(ASR)_智能语音交互-阿里云 https://help.aliyun.com/document_detail/72238.html 返回模式(response mode) ...
- What Is the Linux Lokkit Utility? https://www.lifewire.com/what-is-lokkit-2192255
lokkit: The Lokkit utility attempts to provide firewalling for the average Linux end user. Instead o ...
- /dev/zero和/dev/null的区别
http://www.cnblogs.com/jacktu/archive/2010/06/28/1766791.html /dev/zero和/dev/null的区别 使用/dev/null 把 ...