题目传送门

 /*
题意:宽度为1,高度不等,求最大矩形面积
stack(数组模拟):对于每个a[i]有L[i],R[i]坐标位置 表示a[L[i]] < a[i] < a[R[i]] 的极限情况
st[]里是严格单调递增,若不记录的话还要O(n)的去查找L,R,用栈的话降低复杂度
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <iostream>
using namespace std; typedef long long ll; const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f;
int a[MAXN], L[MAXN], R[MAXN];
int st[MAXN]; int main(void) //POJ 2559 Largest Rectangle in a Histogram
{
// freopen ("POJ_2559.in", "r", stdin); int n;
while (scanf ("%d", &n) == )
{
if (n == ) break;
for (int i=; i<=n; ++i) scanf ("%d", &a[i]);
memset (st, , sizeof (st)); int p = ;
for (int i=; i<=n; ++i)
{
while (p >= && a[st[p-]] >= a[i]) p--;
L[i] = (p == ) ? : st[p-];
st[p++] = i;
} p = ;
for (int i=n; i>=; --i)
{
while (p >= && a[st[p-]] >= a[i]) p--;
R[i] = (p == ) ? n + : st[p-];
st[p++] = i;
} ll ans = ;
for (int i=; i<=n; ++i)
{
ans = max (ans, (ll) a[i] * (R[i] - L[i] - ));
}
printf ("%I64d\n", ans);
} return ;
}

stack(数组模拟) POJ 2559 Largest Rectangle in a Histogram的更多相关文章

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

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

  2. poj 2559 Largest Rectangle in a Histogram 栈

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

  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 -- 动态规划

    题目地址:http://poj.org/problem?id=2559 Description A histogram is a polygon composed of a sequence of r ...

  5. POJ 2559 Largest Rectangle in a Histogram (单调栈或者dp)

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

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

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

  7. POJ 2559 Largest Rectangle in a Histogram(单调栈)

    传送门 Description A histogram is a polygon composed of a sequence of rectangles aligned at a common ba ...

  8. 题解报告:poj 2559 Largest Rectangle in a Histogram(单调栈)

    Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base l ...

  9. POJ 2559 Largest Rectangle in a Histogram

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18942   Accepted: 6083 Description A hi ...

随机推荐

  1. Android时时监測手机的旋转角度 依据旋转角度确定在什么角度载入竖屏布局 在什么时候载入横屏布局

    一.场景描写叙述: 最近开发中遇到个问题,就是我们在做横竖屏切换的功能时.横竖屏布局是操作系统去感知的,作为开发员没法确定Activity在什么时候载入横屏布局,在什么时候载入竖屏布局.因此为了找到载 ...

  2. Linux下进程信息的深入分析

    这里我们主要介绍进程的状态,进程的状态可以通过/proc/PID/status来查看,也可以通过/proc/PID/stat来查看. 如果说到工具大家用的最多的ps也可以看到进程的信息.这里我们通过/ ...

  3. 使用VLC搭建视频直播服务器

    去年我们信息之夜我们进行过视频直播服务,当时我们使用了WMS(Windows Media Server)实现了这个服务,但是编码是微软的WMV,因而像iPhone/Android这样的智能手机无法观看 ...

  4. superCleanMaster

    https://github.com/eltld/superCleanMaster

  5. 【iOS-Tips】-工具Tip

    [iOS-Tips]-工具Tip 1.Xcode自带头文件的路径 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulato ...

  6. jquery获取兄弟元素

    按照w3c school的指引,jquery中,要获得一个元素的兄弟,可以用 prev().next()两种方法.顾名思义,prev()获得前一个,next()获得后面一个. 问题是,如果存在前后兄弟 ...

  7. Synthesizing Images of Humans in Unseen Poses

    Synthesizing Images of Humans in Unseen Poses balakg/posewarp-cvpr2018 https://github.com/balakg/pos ...

  8. Delphi的goto语法

    今天第一次主要到Delphi也有goto语法,特别是其奇怪的label声明.估计主要是用来跳出多重循环,而且还真有人使用这种方式.记个笔记: procedure TForm1.btn3Click(Se ...

  9. mongo14-----group,aggregate,mapReduce

    group,aggregate,mapReduce 分组统计: group() 简单聚合: aggregate() 强大统计: mapReduce() db.collection.group(docu ...

  10. NDK编程中如何在C文件中打印调试信息

      1,在Android.mk文件中加上 LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog LOCAL_PATH := $(call my-dir)include ...