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/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 19316 Accepted Submission(s): 5829

Usually, histograms are used to represent discrete distributions, e.g., the frequencies of characters in texts. Note that the order of the rectangles, i.e., their heights, is important. Calculate the area of the largest rectangle in a histogram that is aligned at the common base line, too. The figure on the right shows the largest aligned rectangle for the depicted histogram.
4 1000 1000 1000 1000
0
4000
#include <algorithm>
#include <cstdio> using namespace std; #define LL long long
const int N(+);
LL n,top,ans;
LL l[N],r[N],h[N]; inline void read(LL &x)
{
x=; LL ch=getchar();
for(;ch>''||ch<'';) ch=getchar();
for(;ch>=''&&ch<='';ch=getchar()) x=ch-''+x*;
} int main()
{
for(ans=-;;ans=-)
{
read(n);if(!n) break;
for(int i=;i<=n;i++)
read(h[i]),l[i]=r[i]=i;
for(int i=;i<=n;i++)
for(;l[i]>&&h[l[i]-]>=h[i];)
l[i]=l[l[i]-];
for(int i=n-;i>=;i--)
for(;r[i]<n&&h[r[i]+]>=h[i];)
r[i]=r[r[i]+];
for(int i=;i<=n;i++)
ans=max(ans,(r[i]-l[i]+)*h[i]);
printf("%lld\n",ans);
}
return ;
}
HDU——T 1506 Largest Rectangle in a Histogram|| POJ——T 2559 Largest Rectangle in a Histogram的更多相关文章
- 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 ...
- POJ 2559 Largest Rectangle in a Histogram
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18942 Accepted: 6083 Description A hi ...
- 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 ...
随机推荐
- 上传canvas图片到服务器
canvas绘图后用 canvasDom.toDataURL()可以得到png格式图片的base64 dataURI 然后用ajax post给后台 ,后端程序把开头的data:image/png; ...
- less12 函数
less .x(1) { x:11 } .x(2) { y:22 } .x(@x:1) when (default()) {z:@x} //default()表示一直为真 body{ backgrou ...
- jquery去重
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title> ...
- Sequences of sequences
I have focused on lists of tuples, but almost all the examples in this chapter also work with lists ...
- C#线程安全打开/保存文件对话框
在多线程单元模式(MTA)中为应用程序使用.NET OpenFileDialog和SaveFileDialog 下载FileDialogsThreadAppartmentSafe_v1.zip 如果您 ...
- 洛谷 P1501 [国家集训队]Tree II Link-Cut-Tree
Code: #include <cstdio> #include <algorithm> #include <cstring> #include <strin ...
- yii2.0缓存篇之页面缓存
页面缓存: 如果整个页面都不会发生改变,就可以使用页面缓存缓存整个页面. public function behaviors(){ //此方法[也叫行为]会提前控制器内其他方法执 ...
- HDU 4928 Series 2
有了题解以后这题就成了一个模拟题.不过写了好久才把它写对…… Sad #include <iostream> #include <cstdio> #include <cs ...
- 第五讲 自对偶的Yang-Mills方程及Polyakov和t'Hooft解
$\newcommand{\R}{\mathbb{R}}$以下我们考虑的是$\R^4$或者$S^4$上的Yang-Mills泛函,它们是共形不变的. 一.自对偶和反自对偶 我们寻找$\R^4$或$S^ ...
- ArcGIS api for javascript——加载图标
描述 这个示例展示了如何能用一个动画图片显示地图正在加载.在这个示例中,图片是一个小的动画GIF.当地图第一次加载或用户缩放和平移地图时显示图片.当所有图层加载完成图片消失. 这个示例是通过event ...