Terrible Sets
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 3017 | Accepted: 1561 |
Description
Define set B = {< x, y > | x, y ∈ R and there exists an index i > 0 such that 0 <= y <= hi ,∑0<=j<=i-1wj <= x <= ∑0<=j<=iwj}
Again, define set S = {A| A = WH for some W , H ∈ R+ and there exists x0, y0 in N such that the set T = { < x , y > | x, y ∈ R and x0 <= x <= x0 +W and y0 <= y <= y0 + H} is contained in set B}.
Your mission now. What is Max(S)?
Wow, it looks like a terrible problem. Problems that appear to be terrible are sometimes actually easy.
But for this one, believe me, it's difficult.
Input
Output
Sample Input
3
1 2
3 4
1 2
3
3 4
1 2
3 4
-1
Sample Output
12
14
#include"iostream"
#include"stack"
#include"cstdio"
using namespace std;
struct abc
{
int w;
int h;
} data;
int main()
{
int lasth,n,i,ans,curarea,totalw;
while(cin>>n&&n!=-)
{
stack<abc> s;
ans=;
lasth=;
for(i=;i<n;i++)
{
cin>>data.w>>data.h;
if(data.h>=lasth)
{
lasth=data.h;
s.push(data);
}
else
{
totalw=;
curarea=;
while(!s.empty()&&s.top().h>=data.h)
{
totalw+=s.top().w;
curarea=totalw*s.top().h;
if(curarea>ans)
ans=curarea;
s.pop();
}
totalw+=data.w;
data.w=totalw;
s.push(data);
}
}
totalw=;
curarea=;
while(!s.empty())
{
totalw+=s.top().w;
curarea=totalw*s.top().h;
if(curarea>ans)
ans=curarea;
s.pop();
}
cout<<ans<<endl;
}
return ;
}
Terrible Sets的更多相关文章
- POJ 2082 Terrible Sets
Terrible Sets Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 2747 Accepted: 1389 Des ...
- 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 ...
- poj2082 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(栈)
Description Let N be the set of all natural numbers {0 , 1 , 2 , . . . }, and R be the set of all re ...
- PKU 2082 Terrible Sets(单调栈)
题目大意:原题链接 一排紧密相连的矩形,求能构成的最大矩形面积. 为了防止栈为空,所以提前加入元素(0,0). #include<cstdio> #include<stack> ...
- POJ 2082 Terrible Sets(单调栈)
[题目链接] http://poj.org/problem?id=2082 [题目大意] 给出一些长方形下段对其后横向排列得到的图形,现在给你他们的高度, 求里面包含的最大长方形的面积 [题解] 我们 ...
- stack(单调栈) POJ 2082 Terrible Sets
题目传送门 题意:紧贴x轴有一些挨着的矩形,给出每个矩形的长宽,问能组成的最大矩形面积为多少 分析:用堆栈来维护高度递增的矩形,遇到高度小的,弹出顶部矩形直到符合递增,顺便计算矩形面积,且将弹出的宽度 ...
- 别人整理的DP大全(转)
动态规划 动态规划 容易: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ...
随机推荐
- Java ArrayList Sort
Collections.sort(hits_list, new Comparator<ScoreDoc>(){ @Override public int compare(ScoreDoc ...
- 基于Node.js的实时推送 juggernaut
基于Node.js的实时推送 juggernaut Juggernaut 基于 Node.js 构建.为浏览器和服务器端提供一个实时的连接,可在客户端和服务器端进行数据的实时推送,适合多角色游戏.聊天 ...
- Apache Spark Tachyon的简介
Tachyon是一个分布式内存文件系统,可以理解为内存中的HDFS. 为了提供更高的性能,将数据存储剥离Java Heap. 用户可以基于Tachyon实现RDD或者文件的跨应用共享,并提供高容错机制 ...
- 发现UC/OS-III源码有一处不明白!会不会是BUG.高手过来看看!
http://www.amobbs.com/archiver/tid-4939669.html ———————————————————————————————————————————————————— ...
- source insight 支持CC 文件
今天开始阅读LevelDB的代码,用source insight建立工程,但其不支持cc后缀的C++文件. 找到这篇<source insight看cc文件> 解决的根本办法:Option ...
- JVM基础知识(1)-JVM内存区域与内存溢出
JVM基础知识(1)-JVM内存区域与内存溢出 0. 目录 什么是JVM 运行时数据区域 HotSpot虚拟机对象探秘 OutOfMemoryError异常 1. 什么是JVM 1.1. 什么是JVM ...
- Android:从程序员到架构师之路Ⅲ_高焕堂
Part-2: 从Android框架代码中学习设计 一 基础设计模式(Pattern)的代码:以Android为例 1.Template Method模式:IoC(控制反转)机制 2.Observer ...
- jquery页面加载的时候加载函数
http://blog.csdn.net/tjcyjd/article/details/6713474 jQuery 页面加载初始化的方法有3种 ,页面在加载的时候都会执行脚本,应该没什么区别,主要看 ...
- [置顶] 文件和目录(二)--unix环境高级编程读书笔记
在linux中,文件的相关信息都记录在stat这个结构体中,文件长度是记录在stat的st_size成员中.对于普通文件,其长度可以为0,目录的长度一般为1024的倍数,这与linux文件系统中blo ...
- matlab eps中文乱码的解决方法
直接存成eps总是乱码 最优解决方法是matlab print 保存成jpg,之后用adobe acrobat pro 打开jpg文件另存为eps