【题目链接】

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的更多相关文章

  1. 【题解】Largest Rectangle in a Histogram [SP1805] [POJ2559]

    [题解]Largest Rectangle in a Histogram [SP1805] [POJ2559] [题目描述] 传送: \(Largest\) \(Rectangle\) \(in\) ...

  2. 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 ...

  3. poj 2559 Largest Rectangle in a Histogram (单调栈)

    http://poj.org/problem?id=2559 Largest Rectangle in a Histogram Time Limit: 1000MS   Memory Limit: 6 ...

  4. [POJ 2559]Largest Rectangle in a Histogram 题解(单调栈)

    [POJ 2559]Largest Rectangle in a Histogram Description A histogram is a polygon composed of a sequen ...

  5. poj 2559 Largest Rectangle in a Histogram 栈

    // poj 2559 Largest Rectangle in a Histogram 栈 // // n个矩形排在一块,不同的高度,让你求最大的矩形的面积(矩形紧挨在一起) // // 这道题用的 ...

  6. stack(数组模拟) POJ 2559 Largest Rectangle in a Histogram

    题目传送门 /* 题意:宽度为1,高度不等,求最大矩形面积 stack(数组模拟):对于每个a[i]有L[i],R[i]坐标位置 表示a[L[i]] < a[i] < a[R[i]] 的极 ...

  7. 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 ...

  8. Largest Rectangle in a Histogram【单调栈模板】

    Largest Rectangle in a Histogram 题目链接(点击)来源poj 2559 A histogram is a polygon composed of a sequence ...

  9. poj 2559 Largest Rectangle in a Histogram - 单调栈

    Largest Rectangle in a Histogram Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19782 ...

随机推荐

  1. JavaScipt30(第八个案例)(主要知识点:canvas)

    承接上文,这是第8个案例,要实现的效果是按住鼠标不放,进行拖动时可以在画布上画出不同粗细不同颜色的曲线. 附上项目链接: https://github.com/wesbos/JavaScript30 ...

  2. ORB-SLAM2:一种开源的VSLAM方案(译文)

    摘要: ORB-SLAM2是基于单目,双目和RGB-D相机的一套完整的SLAM方案.它能够实现地图重用,回环检测和重新定位的功能.无论是在室内的小型手持设备,还是到工厂环境的无人机和城市里驾驶的汽车, ...

  3. 通过HTTP的HEADER完成各种骚操作

    作为一名专业的切图工程师,我从来不care网页的header,最多关心Status Code是不是200.但是HEADER真的很重要啊,客户端从服务器端获取内容,首先就是通过HEADER进行各种沟通! ...

  4. UVA - 12589 Learning Vector(dp-01背包)

    题目: 思路: dp[j][h]表示选取了j个向量,且高度为h,利用01背包来解决问题. 没选当前的向量:dp[j][h] = dp[j][h]; 选了当前的向量:dp[j][h] = dp[j-1] ...

  5. Python面向对象之面向对象基本概念

    面向过程和面向对象概念 过程和函数:过程类似于函数,只能执行,但是没有返回结果:函数不仅能执行,还能返回结果. 面向过程和面向对象 基本概念 面向过程-怎么做 把完成某一个需求的所有步骤从头到尾逐步实 ...

  6. 【Codeforces 922D】Robot Vacuum Cleaner

    [链接] 我是链接,点我呀:) [题意] 让你把n个字符串重新排序,然后按顺序连接在一起 使得这个组成的字符串的"sh"子序列最多 [题解] /* * 假设A的情况好于B * 也就 ...

  7. image url to base64

    image url to base64 https://www.base64-image.de/ https://www.browserling.com/tools/image-to-base64 h ...

  8. [NOI2000] 单词查找树

    ★★   输入文件:trie.in   输出文件:trie.out   简单对比 时间限制:1 s   内存限制:128 MB 在进行文法分析的时候,通常需要检测一个单词是否在我们的单词列表里.为了提 ...

  9. javamail中的 javax.mail.AuthenticationFailedException: failed to connect的解决

    在163邮箱中开启POP3和SMTP服务,并设置客户端授权密码,用该密码登录.而不是用户的密码.

  10. 13、Java并发性和多线程-Java Volatile关键字

    以下内容转自http://tutorials.jenkov.com/java-concurrency/volatile.html(使用谷歌翻译): Java volatile关键字用于将Java变量标 ...