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

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

3
1 2
3 4
1 2
3
3 4
1 2
3 4
-1

Sample Output

12
14

Source

 
【题解】
先看暴力做法
以每一个方块为起点,看他能向右拓展到什么地方,这块面积来更新答案,复杂度n^2
这种东西很套路,就是用单调栈维护。
我们以向左延伸为例
我们不难发现如果突然递减,那么小的那个将制约前面的向右延伸,前面比他高的就等价于与他同高度了
于是弹出来就可以了
答案需要在如下几个地方更新:
1、一整个大方块
2、弹出的时候,累加宽度,乘这个小的高度,表示向左能延伸到什么地方。然后用累加高度和这个笑的高度
虚拟一个新的方块压到栈里面
3、扫完后,把整个栈慢慢弹出,累加宽度更新答案
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#define max(a, b) ((a) < (b) ? (b) : (a)) const int MAXN = + ; inline void read(int &x)
{
x = ;char ch = getchar(), c = ch;
while(ch < '' || ch > '')c = ch, ch = getchar();
while(ch <= '' && ch >= '')x = x * + ch - '', ch = getchar();
if(c == '-')x = -x;
} int n,w,h,stackw[MAXN],stackh[MAXN],top,ans; int main()
{
while(scanf("%d", &n) != EOF && n != -)
{
read(stackw[++top]), read(stackh[top]);
ans = stackw[top] * stackh[top];
register int lei = ;
for(register int i = ;i <= n;++ i)
{
read(w), read(h);
ans = max(ans, w * h);
if(h < stackh[top])
{
lei = ;
while(h < stackh[top])
{
lei += stackw[top];
ans = max(ans, lei * stackh[top]);
-- top;
}
stackh[++top] = h;
stackw[top] = lei;
}
stackh[++top] = h;
stackw[top] = w;
}
lei = ;
while(top)
{
lei += stackw[top];
ans = max(ans, lei * stackh[top]);
-- top;
}
printf("%d\n", ans);
}
return ;
}

POJ2082

 

POJ2082 Terrible Sets的更多相关文章

  1. poj2082 Terrible Sets(单调栈)

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

  2. POJ 2082 Terrible Sets

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

  3. Terrible Sets

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

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

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

  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. webpack 打包生成的index 路径引用不对

    webpack 在打包时在访问打包里面的index时,出现路径错误 修改方法为 解决方法:在config下面的index.js把 assetsPublicPath: '/', 修改为: assetsP ...

  2. HZOI20190908模拟40 队长快跑,影魔,抛硬币 题解

    题面:https://www.cnblogs.com/Juve/articles/11487699.html 队长快跑: 权值线段树与dp yy的不错 #include<iostream> ...

  3. css3的3D变形

    一.坐标系 1.是我们熟悉的右手坐标系:伸出右手,让拇指和食指成L形,大拇指向为右,食指向上,中指指向前方,这样,拇指.食指.中指的指向分别是X.Y.Z轴的正方向. 2.是我们CSS3中的3D坐标:伸 ...

  4. MySQL实战总结

    极客上买了<MySQL实战45讲>,用导图大致总结后,跟大家分享下

  5. MYSQL数据库练习题操作(select)大全

    1.创建表 表一:student学生use) .create table student( sno ) primary key not null comment'学号(主码)', sname ) no ...

  6. PAT甲级——A1029 Median

    Given an increasing sequence S of N integers, the median is the number at the middle position. For e ...

  7. if _name_ == " _main_"

    1.作用 py文件有2种使用方法,第1是自己本脚本自己独立执行:第2是被import到其他文件脚本中执行. if  _name_ == " _main_" 该语句控制其他下一步的脚 ...

  8. 解读Python中 locals() 和 globals() 内置函数

    首先globals() 和 locals() 是作用于作用域下的内置函数,所以我将它们分为作用域类型的内置函数 1.作用域相关: 1)globals() # 返回全局作用域中的所有名字 2)local ...

  9. 使用Maven编译运行Storm入门代码(Storm starter)(转)

    Storm 官方提供了入门代码(Storm starter),即 Storm安装教程 中所运行的实例(storm-starter-topologies-0.9.6.jar),该入门代码位于 /usr/ ...

  10. MySQL双机热备份配置

    双机热备份,即能够把主数据库中所有的数据同时写到备份的数据库中,从而实现MySQL数据库的热备份. MySQL Replication是MySQL提供的一种主从备份的机制,并且整个复制备份过程是异步进 ...