【POJ 2559】 Largest Rectangle in a Histogram
【题目链接】
http://poj.org/problem?id=2559
【算法】
单调栈
【代码】
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 100010 int i,top,n;
long long a[MAXN],s[MAXN],w[MAXN],stk[MAXN];
long long ans,tmp; int main()
{ while (scanf("%d",&n) != EOF && n)
{
for (i = ; i <= n; i++) scanf("%lld",&a[i]);
ans = -;
a[++n] = -;
s[top = ] = -;
for (i = ; i <= n; i++)
{
if (a[i] >= s[top])
{
s[++top] = a[i];
w[top] = ;
} else
{
tmp = ;
while (a[i] < s[top])
{
tmp += w[top];
ans = max(ans,tmp*s[top]);
top--;
}
s[++top] = a[i]; w[top] = tmp + ;
}
}
printf("%lld\n",ans);
} return ; }
【POJ 2559】 Largest Rectangle in a Histogram的更多相关文章
- 【题解】Largest Rectangle in a Histogram [SP1805] [POJ2559]
[题解]Largest Rectangle in a Histogram [SP1805] [POJ2559] [题目描述] 传送: \(Largest\) \(Rectangle\) \(in\) ...
- 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]] 的极 ...
- 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 ...
- Largest Rectangle in a Histogram【单调栈模板】
Largest Rectangle in a Histogram 题目链接(点击)来源poj 2559 A histogram is a polygon composed of a sequence ...
- poj 2559 Largest Rectangle in a Histogram - 单调栈
Largest Rectangle in a Histogram Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19782 ...
随机推荐
- ANNOTATION and analyse hello1.java
一.What is annotation? annotation的中文意思就是注解,注释的意思.注解也属于一种类型.它是在 Java SE 5.0 版本中开始引入的概念.它的形式跟接口很类似,不过前面 ...
- vue组件---动态组件之多标签页面
首先看下效果图 代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> & ...
- 第二节:1_C#中的委托的使用和讲解(转)
C# 中的委托 引言 委托 和 事件在 .Net Framework中的应用非常广泛,然而,较好地理解委托和事件对很多接触C#时间不长的人来说并不容易.它们就像是一道槛儿,过了这个槛的人,觉得真是太容 ...
- form表单中只有一个input时,按回车键后表单自动提交(form表单的一个小坑)
form中只有一个input按回车键表单会自动提交 在一个form表单中,若只有一个input,按回车键表单会自动提交,但是当表单中存在多个input时,按回车键不会执行任何操作,这是form表单的一 ...
- TWaver GIS制作穹顶之下的雾霾地图
“我不满意,我不想等待,我也不再推诿,我要站出来做一点什么.我要做的事,就在此时,就在此刻,就在此地,就在此生”.自离职央视后,沉寂许久的知名记者.主持人柴静昨日携个人视频新作 <穹顶之下> ...
- php第二十九节课
文件 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.o ...
- 10JDBC、CURD、XML、XPath
10JDBC.CURD.XML.XPath-2018/07/20 1.JDBC JDBC:java database connectivity JDBC与数据库驱动的关系:接口与实现的关系. JDBC ...
- 洛谷——P1850 换教室
P1850 换教室 有 2n 节课程安排在 nn 个时间段上.在第 i个时间段上,两节内容相同的课程同时在不同的地点进行,其中,牛牛预先被安排在教室 $c_i$ 上课,而另一节课程在教室 $d_i$ ...
- 「 RQNOJ PID204 」 特种部队
解题思路 看了一下题解,感觉题解貌似有些错误.所以把我的见解放在这里,希望路过的大佬可以帮忙解释一下 QAQ 就是这里的更新 $dp[i-1][i]$ 和 $dp[i][i-1]$ 的时候,之前博主说 ...
- printf函数压栈(i++/i--,++i/--i) 终极解密
#include <stdio.h> void main() { ; printf("%d %d %d %d\n", i, --i, i, i--); } 输出是“3 ...