Terrible Sets
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 3017   Accepted: 1561

Description

Let N be the set of all natural numbers {0 , 1 , 2 , . . . }, and R be the set of all real numbers. wi, hi for i = 1 . . . n are some elements in N, and w0 = 0. 
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

The input consists of several test cases. For each case, n is given in a single line, and then followed by n lines, each containing wi and hi separated by a single space. The last line of the input is an single integer -1, indicating the end of input. You may assume that 1 <= n <= 50000 and w1h1+w2h2+...+wnhn < 109.

Output

Simply output Max(S) in a single line for each case.

Sample Input

  1. 3
  2. 1 2
  3. 3 4
  4. 1 2
  5. 3
  6. 3 4
  7. 1 2
  8. 3 4
  9. -1

Sample Output

  1. 12
  2. 14
  1. #include"iostream"
  2. #include"stack"
  3. #include"cstdio"
  4. using namespace std;
  5. struct abc
  6. {
  7. int w;
  8. int h;
  9. } data;
  10. int main()
  11. {
  12. int lasth,n,i,ans,curarea,totalw;
  13. while(cin>>n&&n!=-)
  14. {
  15. stack<abc> s;
  16. ans=;
  17. lasth=;
  18. for(i=;i<n;i++)
  19. {
  20. cin>>data.w>>data.h;
  21. if(data.h>=lasth)
  22. {
  23. lasth=data.h;
  24. s.push(data);
  25. }
  26. else
  27. {
  28. totalw=;
  29. curarea=;
  30. while(!s.empty()&&s.top().h>=data.h)
  31. {
  32. totalw+=s.top().w;
  33. curarea=totalw*s.top().h;
  34. if(curarea>ans)
  35. ans=curarea;
  36. s.pop();
  37. }
  38. totalw+=data.w;
  39. data.w=totalw;
  40. s.push(data);
  41. }
  42. }
  43. totalw=;
  44. curarea=;
  45. while(!s.empty())
  46. {
  47. totalw+=s.top().w;
  48. curarea=totalw*s.top().h;
  49. if(curarea>ans)
  50. ans=curarea;
  51. s.pop();
  52. }
  53. cout<<ans<<endl;
  54. }
  55. return ;
  56. }

Terrible Sets的更多相关文章

  1. POJ 2082 Terrible Sets

    Terrible Sets Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 2747   Accepted: 1389 Des ...

  2. POJ-2081 Terrible Sets(暴力,单调栈)

    Terrible Sets Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 4113 Accepted: 2122 Descrip ...

  3. POJ2082 Terrible Sets

    Terrible Sets Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5067   Accepted: 2593 Des ...

  4. poj2082 Terrible Sets(单调栈)

    Description Let N be the set of all natural numbers {0 , 1 , 2 , . . . }, and R be the set of all re ...

  5. 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 ...

  6. PKU 2082 Terrible Sets(单调栈)

    题目大意:原题链接 一排紧密相连的矩形,求能构成的最大矩形面积. 为了防止栈为空,所以提前加入元素(0,0). #include<cstdio> #include<stack> ...

  7. POJ 2082 Terrible Sets(单调栈)

    [题目链接] http://poj.org/problem?id=2082 [题目大意] 给出一些长方形下段对其后横向排列得到的图形,现在给你他们的高度, 求里面包含的最大长方形的面积 [题解] 我们 ...

  8. stack(单调栈) POJ 2082 Terrible Sets

    题目传送门 题意:紧贴x轴有一些挨着的矩形,给出每个矩形的长宽,问能组成的最大矩形面积为多少 分析:用堆栈来维护高度递增的矩形,遇到高度小的,弹出顶部矩形直到符合递增,顺便计算矩形面积,且将弹出的宽度 ...

  9. 别人整理的DP大全(转)

    动态规划 动态规划 容易: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ...

随机推荐

  1. HDFS体系结构

    HDFS的设计目标 检测以及快速恢复硬件问题. 流式的数据访问. 移动计算比移动数据的代价小. 简化一致性模型. 超大规模数据集 异构软硬件平台之间的可移植性. HDFS的结构模型HDFS是一个主从的 ...

  2. C语言的指针移位问题

    先贴代码 #include <stdio.h> int main(void) { double a[]={1.1,2.2,3.3}; unsigned int b,c,d; b=& ...

  3. nodejs+express +jade模板引擎 新建项目

    先 安装 nodejsiDEAAM 2015/7/16 22:47:25然后安装 npm install expressiDEAAM 2015/7/16 22:47:35然后安装 npm instal ...

  4. VB调用控制面板

    控制面板 模块: control.exe 命令: rundll32.exe shell32.dll,Control_RunDLL 结果: 显示控制面板窗口. 例子: Dim x x = Shell(& ...

  5. vim 操作

    vim -b test.bin vim 的 -b 选项是告诉 vim 打开的是一个二进制文件,不指定的话,会在后面加上 0x0a ,即一个换行符,这样若是二进制文件,则文件被改变了,后面多了一个0x0 ...

  6. 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, ...

  7. [HDU 4089]Activation[概率DP]

    题意: 有n个人排队等着在官网上激活游戏.Tomato排在第m个. 对于队列中的第一个人.有以下情况: 1.激活失败,留在队列中等待下一次激活(概率为p1) 2.失去连接,出队列,然后排在队列的最后( ...

  8. Model First:创建实体数据模型(ADO.NET 实体数据模型)

    Microsoft Entity Framework是一个对象关系映射工具(Object Relational Mapping ,O/RM)工具.它可以让你从一个数据库自动地生成数据接入层.实体框架免 ...

  9. win8 或 win2008 系统 TFS 打开或获取源代码非常慢

    最近刚更新了win8.1 .打开VS2012后,准备签出个文件,突然发现速度非常慢.打开个TFS目录都要过10多秒才能看到所有子内容.一开始以为是VS的问题更新了U4补丁.结果还是一样.后来googl ...

  10. 项目经验之:GIS的初步工作窗体的搭建

    不多说了,上图,初步工作刚好完 GIS平台系统,实现整个供水系统的协调与统一.系统以管网为基础依据,建立可实现供水管网规划设计.输配管理.图档管理.抢修辅助决策及综合查询.统计等功能. 整体窗口设计 ...