PKU 2082 Terrible Sets(单调栈)
题目大意:原题链接
一排紧密相连的矩形,求能构成的最大矩形面积。
为了防止栈为空,所以提前加入元素(0,0).
#include<cstdio>
#include<stack>
#define maxn 50005
using namespace std;
struct Element
{
int length;
int height;
Element(){}
Element(int _w,int _h){
length=_w,height=_h;
}
}e[maxn];
int n,curlength,curheight,curArea,maxArea;
stack<Element> S;
int get_Max()
{
S.push(Element(,));
maxArea=;
for(int i=;i<=n;i++){
curheight=e[i].height;
curlength=;
while(S.top().height>curheight){
Element now=S.top();
S.pop();
curlength+=now.length;
curArea=curlength*now.height;
if(curArea>maxArea)
maxArea=curArea;
}
curlength+=e[i].length;
S.push(Element(curlength,curheight));
}
return maxArea;
}
int main()
{
while(scanf("%d",&n),n!=-){
for(int i=;i<n;i++)
scanf("%d%d",&e[i].length,&e[i].height);
e[n].height=e[n].length=;
int ans=get_Max();
printf("%d\n",ans);
}
return ;
}
PKU 2082 Terrible Sets(单调栈)的更多相关文章
- POJ 2082 Terrible Sets(栈)
Description Let N be the set of all natural numbers {0 , 1 , 2 , . . . }, and R be the set of all re ...
- POJ 2082 Terrible Sets(单调栈)
[题目链接] http://poj.org/problem?id=2082 [题目大意] 给出一些长方形下段对其后横向排列得到的图形,现在给你他们的高度, 求里面包含的最大长方形的面积 [题解] 我们 ...
- POJ 2082 Terrible Sets
Terrible Sets Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 2747 Accepted: 1389 Des ...
- Terrible Sets_单调栈
Description Let N be the set of all natural numbers {0 , 1 , 2 , . . . }, and R be the set of all re ...
- stack(单调栈) POJ 2082 Terrible Sets
题目传送门 题意:紧贴x轴有一些挨着的矩形,给出每个矩形的长宽,问能组成的最大矩形面积为多少 分析:用堆栈来维护高度递增的矩形,遇到高度小的,弹出顶部矩形直到符合递增,顺便计算矩形面积,且将弹出的宽度 ...
- POJ-2081 Terrible Sets(暴力,单调栈)
Terrible Sets Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 4113 Accepted: 2122 Descrip ...
- POJ2082 Terrible Sets
Terrible Sets Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5067 Accepted: 2593 Des ...
- 【DP/单调栈】关于单调栈的一些题目(codevs 1159,codevs 2673)
CODEVS 2673:Special Judge 题目描述 Description 这个月的pku月赛某陈没有参加,因为当时学校在考试[某陈经常逃课,但某陈还没有强大到考试也可以逃掉的程度].何 ...
- 【BZOJ】1628 && 1683: [Usaco2007 Demo]City skyline 城市地平线(单调栈)
http://www.lydsy.com/JudgeOnline/problem.php?id=1628 http://www.lydsy.com/JudgeOnline/problem.php?id ...
随机推荐
- js数字格式化(加千分位逗号)
需求:当金额大于10000时,在作展示的时候,需要加千分位逗号,就是每隔1000要用逗号分隔: 方法一:使用toLocaleString()方法 此方法和toString()方法的区别看这里 < ...
- sdut 面向对象程序设计上机练习十(运算符重载)
面向对象程序设计上机练习十(运算符重载) Time Limit: 1000MS Memory limit: 65536K 题目描写叙述 定义一个复数类Complex,重载运算符"+" ...
- 设置两个WdatePicker的开始时间小于结束时间,结束时间大于开始时间
contract_start_date_id为开始时间ID contract_end_date_id为结束时间ID $("#contract_start_date_id").bin ...
- Python背景知识——学习笔记
诞生于1989圣诞节,阿姆斯特丹.Guido van Rossum(吉多·范罗苏姆). Python Python:解释型.面向对象.动态数据类型 的 高级程序设计语言. 解释型语言:运行的时候将程序 ...
- Python爬虫(五)
源码: import requests from lxml import etree from my_mysql import MysqlConnect mc = MysqlConnect(','ho ...
- Hadoop1.2.1 日志格式说明及启停方式
日志格式: 日志名称解析: Hadoop启停的三种方式: . 停止后面的以此类推...... 另外 hadoop-daemons.sh 表示启动多个,比如datanode跟tasktracker在真实 ...
- NUC972 MDK NON-OS
NUC972直接可以在BSP包里模板进行编程,烧录用Nu writer http://www2.keil.com/mdk5/legacy 下载对应的安装包的插件 是直接下载到DDR 里面去运行,所 ...
- JSP内置对象——session
sessionsession表示客户端与服务器的一次会话Web中的session指的是用户在浏览某个网站时,从进入网站到浏览器关闭所进过的这段时间,也就是用户浏览这个网站所花费的时间从上述定义中可以看 ...
- spring-boot Web集群
SpringBoot启动类增加注解 @EnableRedisHttpSession @SpringBootApplication @ImportResource({"classpath:co ...
- 如何自定义JSTL标签与SpringMVC 标签的属性中套JSTL标签报错的解决方法
如何自定义JSTL标签 1.创建一个类,从SimpleTagSupport继承 A) 通过继承可以获得当前JSP页面上的对象,如JspContext I) 实际上可以强转为PageContext II ...