POJ2559最大矩形面积——单调栈
题目:http://poj.org/problem?id=2559
#include<iostream>
#include<cstdio>
using namespace std;
int cnt,l[],r[],q[];
long long n,a[];
int main()
{
while()
{
scanf("%lld",&n);
if(!n)return ;
for(int i=;i<=n;i++)
{
scanf("%lld",&a[i]);
while(a[i]<a[q[cnt]]&&cnt)
r[q[cnt--]]=i;
q[++cnt]=i;
}
while(cnt)r[q[cnt--]]=n+;
for(int i=n;i;i--)
{
while(a[i]<a[q[cnt]]&&cnt)
l[q[cnt--]]=i;
q[++cnt]=i;
}
while(cnt)l[q[cnt--]]=;
long long mx=;
for(int i=;i<=n;i++)
{
long long v=a[i]*(r[i]-l[i]-);//long long
if(v>mx)mx=v;
}
printf("%lld\n",mx);
mx=;//
}
}
POJ2559最大矩形面积——单调栈的更多相关文章
- 51nod 1102 面积最大的矩形(单调栈)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1102 题意: 思路: 做法就是求出每个长方形向左向右所能延伸的最大距离. ...
- Leetcode84. 柱状图中最大的矩形(单调栈)
84. 柱状图中最大的矩形 前置 单调栈 做法 连续区间组成的矩形,是看最短的那一块,求出每一块左边第一个小于其高度的位置,右边也同理,此块作为最短限制.需要两次单调栈 单调栈维护递增区间,每次不满足 ...
- po'j2559 Largest Rectangle in a Histogram 单调栈(递增)
Largest Rectangle in a Histogram Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 29498 ...
- 51nod 1102 面积最大的矩形 (单调栈)
链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1102 思路: 首先介绍下单调栈的功能:利用单调栈,可以找到从左/ ...
- XJOI 3606 最大子矩形面积/LightOJ 1083 Histogram(单调栈/笛卡尔树)
A histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rec ...
- poj 2559 最大矩形面积(单调栈)
题目:输入一个整数n,代表有n个 1(宽度) * h[i](高度)的矩形.接下来n个数依次给定一个矩形高度的高度h[i](i<=n). 求:在给定的依次排列的这堆矩形构成的图形里用一个矩形圈出 ...
- [51nod1102]面积最大的矩形(单调栈||预处理)
题意:求序列上某区间最小值乘区间长度的最大值. 解题关键:很早就在<挑战程序设计竞赛>中见过了,单调栈模板题,注意弹栈时如何处理后面的元素. 法一:单调栈 #include<bits ...
- 51nod 1102 面积最大的矩形 && 新疆大学OJ 1387: B.HUAWEI's billboard 【单调栈】+【拼凑段】(o(n) 或 o(nlog(n))
题面1:  题面2:  两道题除了数据范围不同,没有任何差异,两道题都可以o(n)(单调栈),o(nlog(n))(我自己的做法)解决. 解题思路1:(单调栈) 对于每个点找到右边第一个比它小的位 ...
- Poj 2559 最大矩形面积 v单调栈 分类: Brush Mode 2014-11-13 20:48 81人阅读 评论(0) 收藏
#include<iostream> #include<stack> #include<stdio.h> using namespace std; struct n ...
随机推荐
- 浏览器请求中文乱码(ISO-8859-1 to UTF-8)
String utfString=new String(param.getBytes("iso-8859-1"),"utf-8");
- ** exception error: no match of right hand side value
错误发生的情况是模式匹配失败.对于badmatch异常,很难找到单一的原因,但经常性的原因是你无意间尝试绑定已绑定过的变量.
- IIS6.0发布后对路径“D:\xxx\xxxx\web.config”的访问被拒绝问题的解决方法
原来我本机发布后还是可以直接通过浏览器访问,这几天不知道怎么就不行,终于在网上找到解决方法 IIS发布后访问xxx/xxx/web.config路径被拒绝的问题截图如下: 解决方法: 1.在本地或服务 ...
- URAL 1941
比赛的时候三个点没有优化成功.其实也没有想到哈希成数.然后就变成了只要一个长度和scary相等的区间内所有数字个数都是相等的.那么就是符合题意的.于是.为了不TLE我们不能对txt每个位置遍历 的同时 ...
- Awk 从入门到放弃 (6) Awk模式(Pattern)之二
第一题:从/etc/passwd 匹配以 vmuser开头的用户 grep “^vmuser” /etc/passwd -r -n awk ‘/^vmuser /{print $0}’ / ...
- hadoop redis install (4)
reference: http://dblab.xmu.edu.cn/blog/131/ https://github.com/dmajkic/redis https://blog.csdn ...
- learning shell get script absolute path (3)
Shell get script absolute path [Purpose] Get shell script absolute path [Eevironment] ...
- 2019.1.10 L223
Heavy rains that brought additional pollution downstream last year contributed to the first decline ...
- 清除git以外文件
清除git以外文件 清除git以外文件 git clean -fxd git log 查看某段时刻的log git log --until=2013-11-23 #表示查看2013年11月23日以前的 ...
- calculate MAC,Lisence,Checksum and generate muti-file
/************************************************************************* * calculate MAC,Lisence,C ...