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

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!=-1)
{
stack<abc> s;
ans=0;
lasth=0;
for(i=0;i<n;i++)
{
cin>>data.w>>data.h;
if(data.h>=lasth)
{
lasth=data.h;
s.push(data);
}
else
{
totalw=0;
curarea=0;
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=0;
curarea=0;
while(!s.empty())
{
totalw+=s.top().w;
curarea=totalw*s.top().h;
if(curarea>ans)
ans=curarea;
s.pop();
}
cout<<ans<<endl;
}
return 0;
}

Terrible Sets,布布扣,bubuko.com

时间: 2024-10-11 16:12:08

Terrible Sets的相关文章

poj 2082 Terrible Sets (数据结构 ——栈 STL)

 Terrible Sets Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 2999   Accepted: 1549 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 elem

POJ2082 Terrible Sets

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 element

POJ 2082 Terrible Sets

Terrible Sets Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5325   Accepted: 2713 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 element

stack(单调栈) POJ 2082 Terrible Sets

题目传送门 题意:紧贴x轴有一些挨着的矩形,给出每个矩形的长宽,问能组成的最大矩形面积为多少 分析:用堆栈来维护高度递增的矩形,遇到高度小的,弹出顶部矩形直到符合递增,顺便计算矩形面积,且将弹出的宽度都累积到当前的矩形中,这样最后再扫描一遍,算面积很方便,这题应该算是 POJ 2559 的强化版了 收获:stack的应用,求矩形面积,矩阵相乘,表达式计算 代码: /************************************************ * Author :Running

Terrible Sets(求矩形的最大面积(递增栈))

题意:紧贴x轴有一些相互挨着的矩形,给定每个矩形的长宽,问他们可以形成的最大矩形是多少. Sample Input 3 1 2 3 4 1 2 3 3 4 1 2 3 4 -1 Sample Output 12 14 1 #include <iostream> 2 #include <stack> 3 #include <cstdio> 4 5 using namespace std; 6 7 struct rec{ 8 int w; 9 int h; 10 11 }d

poj 动态规划题目列表及总结

此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276,1322, 1414, 1456, 1458, 1609, 1644, 1664, 1690, 1699, 1740(博弈),1742, 1887, 1926(马尔科夫矩阵,求平衡), 1936, 1952, 1953, 1958, 1959, 1962, 1975,

DP题目列表/弟屁专题

声明: 1.这份列表不是我原创的,放到这里便于自己浏览和查找题目. ※最近更新:Poj斜率优化题目 1180,2018,3709 列表一:经典题目题号:容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1191,1208, 1276, 1322, 1414, 1456, 1458, 1609, 1644, 1664, 1690, 1699, 1740, 1742, 1887, 1926, 1936, 195

[转] POJ DP问题

列表一:经典题目题号:容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1191,1208, 1276, 1322, 1414, 1456, 1458, 1609, 1644, 1664, 1690, 1699, 1740, 1742, 1887, 1926, 1936, 1952, 1953, 1958, 1959, 1962, 1975, 1989, 2018, 2029, 2039, 2063, 20

HOJ 题目分类

转自:http://blog.sina.com.cn/s/blog_65f3869301011a1o.html ******************************************************************************* 简单题(包括枚举,二分查找,(复杂)模拟,基础数据结构(栈.队列),杂题等 ****************************************************************************