Poj 2559 最大矩形面积 v单调栈 分类: Brush Mode 2014-11-13 20:48 81人阅读 评论(0) 收藏
#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) 收藏的更多相关文章
- poj 2559 最大矩形面积(单调栈)
题目:输入一个整数n,代表有n个 1(宽度) * h[i](高度)的矩形.接下来n个数依次给定一个矩形高度的高度h[i](i<=n). 求:在给定的依次排列的这堆矩形构成的图形里用一个矩形圈出 ...
- Ombrophobic Bovines 分类: POJ 图论 最短路 查找 2015-08-10 20:32 2人阅读 评论(0) 收藏
Ombrophobic Bovines Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16539 Accepted: 3605 ...
- Wormholes 分类: POJ 2015-07-14 20:21 21人阅读 评论(0) 收藏
Wormholes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 35235 Accepted: 12861 Descr ...
- Network Saboteur 分类: 搜索 POJ 2015-08-09 19:48 7人阅读 评论(0) 收藏
Network Saboteur Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10147 Accepted: 4849 Des ...
- 哈希-Snowflake Snow Snowflakes 分类: POJ 哈希 2015-08-06 20:53 2人阅读 评论(0) 收藏
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 34762 Accepted: ...
- 滑雪 分类: POJ 2015-07-23 19:48 9人阅读 评论(0) 收藏
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 83276 Accepted: 31159 Description Mich ...
- DNA Sorting 分类: POJ 2015-06-23 20:24 9人阅读 评论(0) 收藏
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 88690 Accepted: 35644 Descrip ...
- Binary Tree 分类: POJ 2015-06-12 20:34 17人阅读 评论(0) 收藏
Binary Tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6355 Accepted: 2922 Descr ...
- Self Numbers 分类: POJ 2015-06-12 20:07 14人阅读 评论(0) 收藏
Self Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22101 Accepted: 12429 De ...
随机推荐
- Android笔记之调用系统相机拍照
参考链接: 拍照 | Android Developers, Android相机拍照方向旋转的解决方案:ExifInterface - 简书 Demo链接:https://pan.baidu.co ...
- Jmeter----函数助手参数化
要填写开始日期和结束日期和赋值的变量名
- JS对象 Array 数组对象 数组对象是一个对象的集合,里边的对象可以是不同类型的。数组的每一个成员对象都有一个“下标”,用来表示它在数组中的位置,是从零开始的
Array 数组对象 数组对象是一个对象的集合,里边的对象可以是不同类型的.数组的每一个成员对象都有一个"下标",用来表示它在数组中的位置,是从零开始的 数组定义的方法: 1. 定 ...
- windows使用cmd查看、杀死进程
查看某个进程: netstat -ano | findstr 端口号 杀死某个进程: taskkill /f /pid 进程号
- 单行文本截断 text-overflow
div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
- 关于如何正确打开.wlf文件
只简单说明一下保存/打开.wlf需要注意的内容. (1) 保存 在GUI界面保存时,先切换到sim窗口: 用命令行保存时,其格式为: vsim –wlf <wave_file> … (2) ...
- CF Round #427 (Div. 2) C. Star sky [dp]
题目链接就长这样子? time limit per test 2 seconds memory limit per test 256 megabytes Description The Carte ...
- 概率dp——期望水题hdu4405
还是逆推,如果遇到跳板直接继承目标地的期望即可 #include<bits/stdc++.h> using namespace std; #define maxn 200005 doubl ...
- vue中axios使用封装
一.在main.js导入 // 引入axios,并加到原型链中 import axios from 'axios'; Vue.prototype.$axios = axios; import QS f ...
- bzoj 1196: [HNOI2006]公路修建问题(二分+贪心)
传送门 解题思路 看到最大,肯定要先想二分答案.二分之后首先从小到大枚举\(k\)个小于\(lim\)的所有一级公路,然后用并查集连到一起,然后就在剩下的里面从小到大找n-1-k个二级公路,模仿最小生 ...