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 ...
随机推荐
- 破解电信光猫华为HG8120C关闭路由功能方法
昨天电信的工作人员来安装了电信的光纤宽带,使用的是华为HG8120C这款光电转换器与路由器一体机 这导致下级路由无法直接使用PPPOE拨号连接到互联网,且无法使用端口映射来实现外网访问 而华为开放给用 ...
- iOS开发--URL中汉字出现乱码
NSURL *nurl=[[NSURL alloc] initWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF ...
- Vs2012在Linux开发中的应用(5):项目属性的定义
VS的项目属性表实际上是由一系列的XML文件定义的,都存放在C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\2052文件夹下.我们全然能够 ...
- Intel为Google的物联网平台Brillo推出开发板Edison
Brillo* is a solution from Google* for building connected devices. Incorporating aspects of the Andr ...
- Linux 文本编辑
文本编辑: 查看文本内容: cat:将文件连接并显示 -n:显示时将文件每一行编号 tac:类似于cat,但其功能是逆序显示每一行文件 linlin@ubuntu ...
- Python爬虫开发【第1篇】【Scrapy框架】
Scrapy 框架介绍 Scrapy是用纯Python实现一个为了爬取网站数据.提取结构性数据而编写的应用框架. Srapy框架,用户只需要定制开发几个模块就可以轻松的实现一个爬虫,用来抓取网页内容以 ...
- 【iOS系列】-UIImageView帧动画相关属性介绍
UIImageView帧动画相关属性介绍 1:相关属性: //An array of UIImage objects to use for an animation.存放UIImage对象,会按顺序显 ...
- 《C++ Primer Plus》学习笔记3
<C++ Primer Plus>学习笔记3 第8章 函数探幽 ============================================================== ...
- 2016/3/10 PHP环境搭建 LAMP WAMP
1. php成为服务器端的脚本语言.弱类型语言.$ JavaScript是弱类型语言.var Java强类型语言.byte short int long double float boolean 2. ...
- POI异步导入Excel兼容xsl和xlsx
项目架构:spring+struts2+hibernate4+oracle 需求:用户导入excel文件,导入到相应的数据表中,要求提供导入模板,支持xls和xlsx文件 思路分析: 1.提供一个下载 ...