poj 2082 单调栈 ***
和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 2082 单调栈 ***的更多相关文章
- 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 2559 单调栈 ***
给出一系列的1*h的矩形,求矩形的最大面积. 如图: 题解链接:点我 #include <iostream> #include <cstdio> using namespace ...
- poj 2599 单调栈 ***
和poj2082差不多,加了一个宽度的条件 #include<cstdio> #include<cmath> #include<algorithm> #includ ...
- POJ 2082 Terrible Sets(单调栈)
[题目链接] http://poj.org/problem?id=2082 [题目大意] 给出一些长方形下段对其后横向排列得到的图形,现在给你他们的高度, 求里面包含的最大长方形的面积 [题解] 我们 ...
- poj 3415 Common Substrings(后缀数组+单调栈)
http://poj.org/problem?id=3415 Common Substrings Time Limit: 5000MS Memory Limit: 65536K Total Sub ...
随机推荐
- 伪分布模式下执行wordcount实例时报错解决办法
问题1.不能分配内存,错误提示如下: FAILEDjava.lang.RuntimeException: Error while running command to get file permiss ...
- Oracle 客户端配置
nstantclient-basic-nt-12.1.0.1.0\instantclient_12_1下面新建NETWORK文件夹,NETWORK下新建ADMIN文件夹,ADMIN下新建tnsname ...
- Linux命令sed
如果一个文本文件数据比较多,大概有40万条数据,我想取出第500-1000条数据,保存到另一个文件,用linux命令该如何操作? sed -n '500,1000p' 41w.txt > new ...
- Linux的一个暴力破解工具九头蛇hydra
首先还是书写本文的 参考档:http://www.cnblogs.com/mchina/archive/2013/01/01/2840815.html 工具介绍:原文为官方英文解释本人给翻译下 数量最 ...
- java工具类包
Hutool 提供丰富的java方法,其maven引用 <dependency> <groupId>com.xiaoleilu</groupId> <arti ...
- Billboard(线段树)
Billboard Time Limit:8000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit St ...
- java web dao 层和dao 实现层有什么好处
接口是为了屏蔽不同数据库的JDBC实现差异而出现的. 以常见的系统组织结构为例,管理系统里有一个部门department表用于存放部门信息,因为部门下面可能有子部门所以表中的字段要定义成类似树形结构的 ...
- HDU 4858 项目管理(邻接表 暴力模拟)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4858 我们建造了一个大项目!这个项目有n个节点,用很多边连接起来,并且这个项目是连通的! 两个节点间可 ...
- codeforces 258div2 B Sort the Array
题目链接:http://codeforces.com/contest/451/problem/B 解题报告:给出一个序列,要你判断这个序列能不能通过将其中某个子序列翻转使其成为升序的序列. 我的做法有 ...
- UIView 设置背景图片
http://blog.csdn.net/qijianli/article/details/7777268 项目中,可能需要我们为某个视图设置背景图片,而API中UIView没有设置背景图片的方法,那 ...