Largest Rectangle in a Histogram POJ - 2559
很显然是单调栈
这里记录一种新的写法,这种写法基于递推,但是相比之下比单调栈更好写
#include<cstdio>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<stack>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
//#define endl "\n"
#define inf 0x3f3f3f3f
#define me(a,b) memset(a,b,sizeof(a))
#define maxn 100000+5
long long n,a[maxn];
int l[maxn],r[maxn];
stack<long long> st;
long long mx;
void init()
{
mx=;
while(!st.empty())
st.pop();
}
int main()
{
while(cin>>n&&n){
init();
for(int i=;i<=n;i++)
scanf("%I64d",&a[i]),l[i]=r[i]=i;
a[]=;
for(int i=;i<=n;i++){
int now=i;
while(now>&&a[i]<=a[now-]) now=l[now-];
l[i]=now;
}
for(int i=n-;i;i--){
int now=i;
while(now<n&&a[i]<=a[now+]) now=r[now+];
r[i]=now;
}
for(int i=;i<=n;i++)
mx=max(mx,a[i]*(r[i]-l[i]+));
cout<<mx<<endl;
}
}
Largest Rectangle in a Histogram POJ - 2559的更多相关文章
- Largest Rectangle in a Histogram POJ - 2559 (单调栈)
Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base l ...
- 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 ...
- 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 (单调栈)
http://poj.org/problem?id=2559 Largest Rectangle in a Histogram Time Limit: 1000MS Memory Limit: 6 ...
- [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个矩形排在一块,不同的高度,让你求最大的矩形的面积(矩形紧挨在一起) // // 这道题用的 ...
- stack(数组模拟) POJ 2559 Largest Rectangle in a Histogram
题目传送门 /* 题意:宽度为1,高度不等,求最大矩形面积 stack(数组模拟):对于每个a[i]有L[i],R[i]坐标位置 表示a[L[i]] < a[i] < a[R[i]] 的极 ...
- 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 ...
随机推荐
- 题解 SDOI2010 【栗栗的书架】
\[ Preface \] 看到这题洛谷标签有 主席树 ,还以为是什么二维主席树的玄学做法(雾 \[ Description \] 给出一个 \(R×C\) 的矩阵. 一共 \(m\) 次询问,每次询 ...
- 1 使用MySQL
1.1 连接 主机名(localhost) 端口(3306) 一个合法的用户名 用户口令 1.2 选择数据库 USE crashcourse 1.3 了解数据库和表 SHOW databases; s ...
- asp.net core系列 WebAPI 作者:懒懒的程序员一枚
asp.net core系列 36 WebAPI 搭建详细示例一.概述1.1 创建web项目1.2 添加模型类1.3 添加数据库上下文1.4 注册上下文1.5 添加控制器1.6 添加Get方法1.7 ...
- Generator - Python 生成器
Generator, python 生成器, 先熟悉一下儿相关定义, generator function 生成器函数, 生成器函数是一个在定义体中存有 'yield' 关键字的函数. 当生成器函数被 ...
- 自动化测试用例中的raise
1.一次自动化测试学习中,expect异常中包含“raise e”,这是什么意思呢? 2.网上查了一下,大概意思是:若有异常,不会执行一下的操作,但是明明是语句后确实没有其他语句呀. 3.注释掉之后, ...
- 20200120--python学习第12天
今日内容 函数中高级(闭包/高价函数) 内置函数 内置模块(.py文件) 内容回顾 函数基础概念 a.函数基本结构 def func(arg): return arg v1 = func(123) b ...
- ISC BIND DNS
win10,安装BIND9.15.5.x64 安装完成后,计算机服务里启动,总是报无法登陆,但服务属性登陆里设置了密码了啊,就是named,但就是一直报错.后来用下面方法避开了该问题. 安装完成后,服 ...
- 手动发布本地jar包到Nexus私服
1.Nexus配置 1. 在Nexus私服上建立仓库,用于盛放jar包,如名叫3rd_part. 2. 注册用户Nuxus用户,如名叫dev,密码dev_123. 3. 给dev用户分配能访问3rd_ ...
- mysql必知必会--用正则表达式 进行搜索
正则表达式介绍 前两章中的过滤例子允许用匹配.比较和通配操作符寻找数据.对 于基本的过滤(或者甚至是某些不那么基本的过滤),这样就足够了.但 随着过滤条件的复杂性的增加, WHERE 子句本身的复杂性 ...
- 利用js+ajax在jsp与servlet间进行简单数据交换
直接上代码 jsp <%@ page language="java" contentType="text/html; charset=utf-8" pag ...