【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 ...
随机推荐
- js读写txt文件
view plain<script language="javascript" type="text/javascript"> //读文件funct ...
- [Linux]正则表达式和grep使用【转载】
[Linux]正则表达式和grep使用 2018年12月05日 23:45:54 祥知道 阅读数 78 标签: 正则表达式grepLinuxegrep 更多 个人分类: Linux 所属专栏: Li ...
- 01C++编辑编译运行环境
C++编辑编译运行环境 Bloodshed Dev-C++ Microsoft Visual Studio
- 【LeetCode】9、Palindrome Number(回文数)
题目等级:Easy 题目描述: Determine whether an integer is a palindrome. An integer is a palindrome when it rea ...
- C++ string 是否以‘\0’结尾 讨论
转载https://blog.csdn.net/qq_31930499/article/details/80374310 之前在某篇文章中看到,C语言字符串是以’\0’结尾的,但是C++string类 ...
- [Python数据结构] 使用 Circular List实现Queue
[Python数据结构] 使用 Circular List实现Queue 1. Queue队列,又称为伫列(queue),是先进先出(FIFO, First-In-First-Out)的线性表.在具体 ...
- numpy.random模块常用函数解析
numpy.random模块中常用函数解析 numpy.random模块官方文档 1. numpy.random.rand(d0, d1, ..., dn)Create an array of the ...
- Linux mpstat-显示各个可用CPU的状态
更多linux 性能监测与优化 关注:linux命令大全 mpstat命令指令主要用于多CPU环境下,它显示各个可用CPU的状态系你想.这些信息存放在/proc/stat文件中.在多CPUs系统里,其 ...
- PAT 1135 Is It A Red-Black Tree
There is a kind of balanced binary search tree named red-black tree in the data structure. It has th ...
- BNUOJ 2461 Anniversary party
Anniversary party Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. Origi ...