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 ...
随机推荐
- 【NLP】新词发现
http://www.csdn.net/article/2013-05-08/2815186 http://blog.csdn.net/yuyu2223/article/details/7725705 ...
- HttpServletRequest和HttpServletResponse简介
http://blog.csdn.net/tong_xinglong/article/details/12972819
- AWS系列-EC2实例选择镜像
Centos Ubuntu Redhat 打开EC2控制台,点击启动实例,选择AWS Marketplace Centos.org说明为centos官网镜像 如下图,这种镜像是收费的镜像 Ubuntu ...
- Spring_day04--整合struts2和spring框架
整合struts2和spring框架 1 把struts2的action交给spring管理 2 实现过程 第一步 导入struts2和spring的jar包 (1)导入用于整合的jar包 第二步 创 ...
- Struts2_day04--自定义拦截器_Struts2的标签库_表单标签
自定义拦截器 1 在struts2里面有很多的拦截器,这些拦截器是struts2封装的功能,但是在实际开发中,struts2里面的拦截器中可能没有要使用的功能,这个时候需要自己写拦截器实现功能 2 拦 ...
- Struts2_day04--课程介绍_Struts2拦截器概述&底层原理_重要的概念
Struts2_day04 上节内容 今天内容 Struts2拦截器概述 拦截器底层原理 重要的概念 自定义拦截器 自定义登录拦截器 Struts2的标签库 Struts2表单标签(会用) Strut ...
- vue通信
组件实例的作用域是孤立的. 一.父子通信 父组件通过props向下传递数据给子组件,子组件通过events给父组件发送消息. 要让子组件使用父组件的数据,我们需要通过子组件的props选项.prop是 ...
- Spark 源码分析 -- Stage
理解stage, 关键就是理解Narrow Dependency和Wide Dependency, 可能还是觉得比较难理解 关键在于是否需要shuffle, 不需要shuffle是可以随意并发的, 所 ...
- Photoshop打开时报错“不能打开暂存盘文件。。。”
解决方法: 1.找到应用程序(Photoshop.exe文件) 2.右键 -> 属性 -> 兼容性 -> 更改所有用户的设置 -> 勾选上“以管理员身份运行此程序”.
- 属性attribute和property的区别
<!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content ...