#include<iostream>
#include<stack>
#include<stdio.h>
using namespace std;
struct node
{
__int64 num,pre,next;
};
int main()
{
int n;
freopen("in.txt","r",stdin);
while(scanf("%d",&n)>0&&n)
{
stack<node>Q;
node tmp;
__int64 ans=0,sum=0,num;
scanf("%I64d",&tmp.num);
tmp.pre=1;
tmp.next=1;
Q.push(tmp);
for(int i=1;i<n;i++)
{
scanf("%I64d",&tmp.num);
tmp.pre = tmp.next = 1;
while(!Q.empty()&&tmp.num<=Q.top().num)
{
node tmp1=Q.top();
Q.pop();
ans=tmp1.num*(tmp1.pre+tmp1.next-1);
if(!Q.empty())
Q.top().next+=tmp1.next;
tmp.pre+=tmp1.pre;
if(ans>sum)
sum=ans;
}
Q.push(tmp);
}
while(!Q.empty())
{
node tmp1=Q.top();
Q.pop();
if(!Q.empty())
Q.top().next+=tmp1.next;
ans=tmp1.num*(tmp1.pre+tmp1.next-1);
if(ans>sum)
sum=ans;
}
printf("%I64d\n",sum);
}
return 0;
}

实在放心不下这个单调栈,还是把他存到自己博客里面吧

Poj 2559 最大矩形面积 v单调栈 分类: Brush Mode 2014-11-13 20:48 81人阅读 评论(0) 收藏的更多相关文章

  1. poj 2559 最大矩形面积(单调栈)

    题目:输入一个整数n,代表有n个  1(宽度) * h[i](高度)的矩形.接下来n个数依次给定一个矩形高度的高度h[i](i<=n). 求:在给定的依次排列的这堆矩形构成的图形里用一个矩形圈出 ...

  2. Ombrophobic Bovines 分类: POJ 图论 最短路 查找 2015-08-10 20:32 2人阅读 评论(0) 收藏

    Ombrophobic Bovines Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16539 Accepted: 3605 ...

  3. Wormholes 分类: POJ 2015-07-14 20:21 21人阅读 评论(0) 收藏

    Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 35235   Accepted: 12861 Descr ...

  4. Network Saboteur 分类: 搜索 POJ 2015-08-09 19:48 7人阅读 评论(0) 收藏

    Network Saboteur Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10147 Accepted: 4849 Des ...

  5. 哈希-Snowflake Snow Snowflakes 分类: POJ 哈希 2015-08-06 20:53 2人阅读 评论(0) 收藏

    Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 34762 Accepted: ...

  6. 滑雪 分类: POJ 2015-07-23 19:48 9人阅读 评论(0) 收藏

    滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 83276 Accepted: 31159 Description Mich ...

  7. DNA Sorting 分类: POJ 2015-06-23 20:24 9人阅读 评论(0) 收藏

    DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 88690 Accepted: 35644 Descrip ...

  8. Binary Tree 分类: POJ 2015-06-12 20:34 17人阅读 评论(0) 收藏

    Binary Tree Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6355   Accepted: 2922 Descr ...

  9. Self Numbers 分类: POJ 2015-06-12 20:07 14人阅读 评论(0) 收藏

    Self Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22101   Accepted: 12429 De ...

随机推荐

  1. C#枚举转化示例大全,数字或字符串转枚举

    本文重点举例说明C#枚举的用法,数字转化为枚举.枚举转化为数字及其枚举数值的判断,以下是具体的示例: 先举两个简单的例子,然后再详细的举例说明: 字符串转换成枚举:DayOfWeek week=(Da ...

  2. Flutter 集成到现有iOS工程

    前沿 由于我司已经有自己的App,flutter属于技术引进的一部分,也不太可能重新启动一个项目,因此目前我们是将flutter模块形式注入我们的App之中.即:将flutter模块集成到现在有iOS ...

  3. springboot配置多数据源mybatis配置失效问题

    mybatis配置 #开启驼峰映射 mybatis.configuration.map-underscore-to-camel-case=true #开启打印sql mybatis.configura ...

  4. 2018-10-8-3分钟教你搭建-gitea-在-Centos-服务器

    title author date CreateTime categories 3分钟教你搭建 gitea 在 Centos 服务器 lindexi 2018-10-08 09:54:39 +0800 ...

  5. Java获取文件Content-Type(Mime-Type)

    Java获取文件Content-Type(Mime-Type) 刚好工作中要用到,所以总结一下.推荐使用第一种和第三种,实在不行,也可以去把http://tool.oschina.net/common ...

  6. The linux command 之进程

    ******************查看进程********************* 一.使用ps命令 [me@linuxbox ~]$ ps PID TTY TIME CMD pts/ :: ba ...

  7. c_数据结构_二叉树的遍历实现

    #include<stdio.h> #include<stdlib.h> #define OK 1 #define ERROR 0 #define OVERFLOW -2 #d ...

  8. linux 将子文件夹的文件复制到 当前目录中

    linux 将子文件夹的文件复制到 当前目录中,如 目录结构大概是 -sh |__ db_backup |___ test |____ 2018_01_01_00_00_00 |_____ 2018_ ...

  9. Last_SQL_Error: Error 'Can't drop database

    此文办法只用应急, 别的办法我还没想到,  文章是Copy来的 MySQL主从同步报错排错结果及修复过程之:Slave_SQL_Running: No 起因调查: 收到大量邮件报警想必事出有因,就问同 ...

  10. linux上给其他在线用户发送信息(wall, write, talk, mesg)

        linux上给其他在线用户发送信息(wall, write, talk, mesg)   2018-01-05 lonskyMR 转自 恶之一眉 修改 微信分享: 设置登录提示     /et ...