poj 2599 单调栈 ***
和poj2082差不多,加了一个宽度的条件
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
const int MAXN=;
pair<int,int> ele[MAXN];
int main(){
int height, n;
int w;
int i,j,k,h;
int ans, tot, tmp;
int top=;
while (scanf("%d", &n) != EOF && n!=-)
{
top = ;
ans = ;
for(i=;i<n;i++){
tmp=;
scanf("%d%d",&w,&h);
while(top>&&h<ele[top-].first){
int aans=ele[top-].first*(ele[top-].second+tmp);
ans=max(ans,aans);
tmp+=ele[top-].second; //这个比较容易忘,这是当前累计的加上之前累计的
top--;
}
ele[top].first=h;
ele[top].second=w+tmp;
top++;
}
tmp=;
while(top>){
int aans=ele[top-].first*(ele[top-].second+tmp);
ans=max(ans,aans);
tmp+=ele[top-].second;
top--;
}
printf("%d\n", ans); }
return ; }
poj 2599 单调栈 ***的更多相关文章
- Poj 3250   单调栈
		
1.Poj 3250 Bad Hair Day 2.链接:http://poj.org/problem?id=3250 3.总结:单调栈 题意:n头牛,当i>j,j在i的右边并且i与j之间的所 ...
 - poj 2059 单调栈
		
题意:求柱状图中最大矩形面积. 单调栈:顾名思义就是栈内元素单调递增的栈. 每次插入数据来维护这个栈,假设当前须要插入的数据小于栈顶的元素,那就一直弹出栈顶的元素.直到满足当前须要插入的元素大于栈顶元 ...
 - [poj 2796]单调栈
		
题目链接:http://poj.org/problem?id=2796 单调栈可以O(n)得到以每个位置为最小值,向左右最多扩展到哪里. #include<cstdio> #include ...
 - uva 1619 - Feel Good || poj 2796 单调栈
		
1619 - Feel Good Time limit: 3.000 seconds Bill is developing a new mathematical theory for human ...
 - POJ 3044单调栈
		
题意: 思路: 单调栈 // by SiriusRen #include <stack> #include <cstdio> using namespace std; stac ...
 - poj 2082 单调栈 ***
		
和poj2082差不多,加了一个宽度的条件 #include<iostream> #include<string> #include<cmath> #include ...
 - poj 2559 单调栈 ***
		
给出一系列的1*h的矩形,求矩形的最大面积. 如图: 题解链接:点我 #include <iostream> #include <cstdio> using namespace ...
 - poj 3415 Common Substrings(后缀数组+单调栈)
		
http://poj.org/problem?id=3415 Common Substrings Time Limit: 5000MS Memory Limit: 65536K Total Sub ...
 - poj 3250 Bad Hair Day (单调栈)
		
http://poj.org/problem?id=3250 Bad Hair Day Time Limit: 2000MS Memory Limit: 65536K Total Submissi ...
 
随机推荐
- select遍历list默认选中初始值
			
<select id="userstatus" name="userstatus"> <c:forEach items=&qu ...
 - MySQL异步复制延迟解决
			
http://www.ttlsa.com/mysql/mysql-5-7-enhanced-multi-thread-salve/
 - Javascript加速运动与减速运动
			
加速运动,即一个物体运动时速度越来越快:减速运动,即一个物体运动时速度越来越慢.现在用Javascript来模拟这两个效果,原理就是用setInterval或setTimeout动态改变一个元素与另外 ...
 - 就for循环VS for-in循环
			
这种模式的问题在于每次循环迭代的时候都要访问数据的长度.这样会使代码变慢,特别是当myarray不是数据,而是HTML容器对象时. HTML容器是DOM方法返回的对象,如: document.getE ...
 - 用于阻止缓冲区溢出攻击的 Linux 内核参数与 gcc 编译选项
			
先来看看基于 Red Hat 与 Fedora 衍生版(例如 CentOS)系统用于阻止栈溢出攻击的内核参数,主要包含两项: kernel.exec-shield 可执行栈保护,字面含义比较“绕”, ...
 - Socket心跳包机制【转】
			
转自:https://blog.csdn.net/xuyuefei1988/article/details/8279812 心跳包的发送,通常有两种技术 方法1:应用层自己实现的心跳包 由应用程序自己 ...
 - Casper带有4个内建记录级别
			
默认情况下,CasperJS会在‘error’级别过滤日志.所以如果你开始记录日志后没有看到任何东西,可能就是这个原因.为确保显示日志输出,我把它设置为‘debug’.而且我关闭了‘verbose’选 ...
 - MVC 控制器中传递dynamic(对象) 给视图
			
有时候不想重新定义一个实体,则使用 dynamic 来定义匿名类型. //匿名类型 传递到前台 Model dynamic viewModel = new { UserID = 5016 }; ret ...
 - urbuntu12.04 ftp服务器搭建
			
1.安装ftp服务器: sudo apt-get install vsftpd 2..配置ftp 修改ftp的配置文件,该文件在/etc目录下,在终端中键入如下命令以打开配置文件: sudo vi / ...
 - HighCharts、EChart图表X轴纵向显示
			
HighCharts 回调javascript函数来格式化标签,值通过this.value获得,this的其他属性还包括axis, chart, isFirst and isLast. 默认为: fu ...