POJ2082 Terrible Sets
| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 5067 | Accepted: 2593 |
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
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
Sample Input
3
1 2
3 4
1 2
3
3 4
1 2
3 4
-1
Sample Output
12
14
Source
#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的更多相关文章
- 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
Terrible Sets Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 2747 Accepted: 1389 Des ...
- Terrible Sets
Terrible Sets Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3017 Accepted: 1561 Des ...
- POJ-2081 Terrible Sets(暴力,单调栈)
Terrible Sets Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 4113 Accepted: 2122 Descrip ...
- 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大全(转)
动态规划 动态规划 容易: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ...
随机推荐
- webpack 打包生成的index 路径引用不对
webpack 在打包时在访问打包里面的index时,出现路径错误 修改方法为 解决方法:在config下面的index.js把 assetsPublicPath: '/', 修改为: assetsP ...
- HZOI20190908模拟40 队长快跑,影魔,抛硬币 题解
题面:https://www.cnblogs.com/Juve/articles/11487699.html 队长快跑: 权值线段树与dp yy的不错 #include<iostream> ...
- css3的3D变形
一.坐标系 1.是我们熟悉的右手坐标系:伸出右手,让拇指和食指成L形,大拇指向为右,食指向上,中指指向前方,这样,拇指.食指.中指的指向分别是X.Y.Z轴的正方向. 2.是我们CSS3中的3D坐标:伸 ...
- MySQL实战总结
极客上买了<MySQL实战45讲>,用导图大致总结后,跟大家分享下
- MYSQL数据库练习题操作(select)大全
1.创建表 表一:student学生use) .create table student( sno ) primary key not null comment'学号(主码)', sname ) no ...
- PAT甲级——A1029 Median
Given an increasing sequence S of N integers, the median is the number at the middle position. For e ...
- if _name_ == " _main_"
1.作用 py文件有2种使用方法,第1是自己本脚本自己独立执行:第2是被import到其他文件脚本中执行. if _name_ == " _main_" 该语句控制其他下一步的脚 ...
- 解读Python中 locals() 和 globals() 内置函数
首先globals() 和 locals() 是作用于作用域下的内置函数,所以我将它们分为作用域类型的内置函数 1.作用域相关: 1)globals() # 返回全局作用域中的所有名字 2)local ...
- 使用Maven编译运行Storm入门代码(Storm starter)(转)
Storm 官方提供了入门代码(Storm starter),即 Storm安装教程 中所运行的实例(storm-starter-topologies-0.9.6.jar),该入门代码位于 /usr/ ...
- MySQL双机热备份配置
双机热备份,即能够把主数据库中所有的数据同时写到备份的数据库中,从而实现MySQL数据库的热备份. MySQL Replication是MySQL提供的一种主从备份的机制,并且整个复制备份过程是异步进 ...