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大全(转)
动态规划 动态规划 容易: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ...
随机推荐
- HDFS体系结构
HDFS的设计目标 检测以及快速恢复硬件问题. 流式的数据访问. 移动计算比移动数据的代价小. 简化一致性模型. 超大规模数据集 异构软硬件平台之间的可移植性. HDFS的结构模型HDFS是一个主从的 ...
- C语言的指针移位问题
先贴代码 #include <stdio.h> int main(void) { double a[]={1.1,2.2,3.3}; unsigned int b,c,d; b=& ...
- nodejs+express +jade模板引擎 新建项目
先 安装 nodejsiDEAAM 2015/7/16 22:47:25然后安装 npm install expressiDEAAM 2015/7/16 22:47:35然后安装 npm instal ...
- VB调用控制面板
控制面板 模块: control.exe 命令: rundll32.exe shell32.dll,Control_RunDLL 结果: 显示控制面板窗口. 例子: Dim x x = Shell(& ...
- vim 操作
vim -b test.bin vim 的 -b 选项是告诉 vim 打开的是一个二进制文件,不指定的话,会在后面加上 0x0a ,即一个换行符,这样若是二进制文件,则文件被改变了,后面多了一个0x0 ...
- Beginning OpenGL ES 2.0 with GLKit Part 1
Update 10/24/12: If you’d like a new version of this tutorial fully updated for iOS 6 and Xcode 4.5, ...
- [HDU 4089]Activation[概率DP]
题意: 有n个人排队等着在官网上激活游戏.Tomato排在第m个. 对于队列中的第一个人.有以下情况: 1.激活失败,留在队列中等待下一次激活(概率为p1) 2.失去连接,出队列,然后排在队列的最后( ...
- Model First:创建实体数据模型(ADO.NET 实体数据模型)
Microsoft Entity Framework是一个对象关系映射工具(Object Relational Mapping ,O/RM)工具.它可以让你从一个数据库自动地生成数据接入层.实体框架免 ...
- win8 或 win2008 系统 TFS 打开或获取源代码非常慢
最近刚更新了win8.1 .打开VS2012后,准备签出个文件,突然发现速度非常慢.打开个TFS目录都要过10多秒才能看到所有子内容.一开始以为是VS的问题更新了U4补丁.结果还是一样.后来googl ...
- 项目经验之:GIS的初步工作窗体的搭建
不多说了,上图,初步工作刚好完 GIS平台系统,实现整个供水系统的协调与统一.系统以管网为基础依据,建立可实现供水管网规划设计.输配管理.图档管理.抢修辅助决策及综合查询.统计等功能. 整体窗口设计 ...