poj2082 Terrible Sets(单调栈)
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
Source
program rrr(input,output);
var
h,l,r,q,sum:array[..]of longint;
n,i,t,ans,w:longint;
function max(a,b:longint):longint;
begin
if a>b then exit(a) else exit(b);
end;
begin
assign(input,'r.in');assign(output,'r.out');reset(input);rewrite(output);
while true do
begin
readln(n);if n=- then break;
sum[]:=;
for i:= to n do begin readln(w,h[i]);sum[i]:=sum[i-]+w; end;
t:=;q[]:=;
for i:= to n do
begin
while (t>) and (h[i]<=h[q[t]]) do dec(t);
l[i]:=q[t];
inc(t);q[t]:=i;
end;
t:=;q[]:=n+;
for i:=n downto do
begin
while (t>) and (h[i]<=h[q[t]]) do dec(t);
r[i]:=q[t];
inc(t);q[t]:=i;
end;
ans:=;
for i:= to n do ans:=max(ans,h[i]*(sum[r[i]-]-sum[l[i]]));
writeln(ans);
end;
close(input);close(output);
end.
poj2082 Terrible Sets(单调栈)的更多相关文章
- PKU 2082 Terrible Sets(单调栈)
题目大意:原题链接 一排紧密相连的矩形,求能构成的最大矩形面积. 为了防止栈为空,所以提前加入元素(0,0). #include<cstdio> #include<stack> ...
- POJ2082 Terrible Sets
Terrible Sets Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5067 Accepted: 2593 Des ...
- 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 ...
- POJ-2081 Terrible Sets(暴力,单调栈)
Terrible Sets Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 4113 Accepted: 2122 Descrip ...
- POJ 2082 Terrible Sets(单调栈)
[题目链接] http://poj.org/problem?id=2082 [题目大意] 给出一些长方形下段对其后横向排列得到的图形,现在给你他们的高度, 求里面包含的最大长方形的面积 [题解] 我们 ...
- poj2082单调栈
本来实在做后缀数组的题目的,不巧,碰到了pku3415这题,需要用到单调栈来维护,但是之前又没有学习过单调栈这方面的知识,于是水了几题....... 题意:给你一些连续的小矩形,高宽不定,求最大的矩形 ...
- POJ 2082 Terrible Sets
Terrible Sets Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 2747 Accepted: 1389 Des ...
- 【BZOJ】1628 && 1683: [Usaco2007 Demo]City skyline 城市地平线(单调栈)
http://www.lydsy.com/JudgeOnline/problem.php?id=1628 http://www.lydsy.com/JudgeOnline/problem.php?id ...
随机推荐
- css 常用单位
em: 相对于应用在当前元素的字体尺寸,1em 等于当前的字体尺寸,2em 等于当前字体尺寸的两倍,一般浏览器字体大小默认为16px,则2em == 32px: W3原文:font size of t ...
- POJ3468(线段树区间求和+区间查询)
https://vjudge.net/contest/66989#problem/C You have N integers, A1, A2, ... , AN. You need to deal w ...
- 使用Git进行协同开发
用了一段时间github,一直想用时间来对git的使用来做一段笔记,前段时间比较忙,现在沉下心来学习也是极好的. 很多项目开发会采用git这一优秀的分布式版本管理工具来进行项目版本管理.因为git的使 ...
- What's new in XAML of .NET 4.0( .NET 4.0中XAML的新功能 )
原文 What's new in XAML of .NET 4.0 What's new in XAML of .NET 4.0 Easy Object References with {x:Refe ...
- oracle10g安装在裸设备上
参考了百度文库上的 <在裸设备上面安装oracle10g> 一文. 不过为了简单起见,我选择OS 为 Redhat AS 4.8 32位. 准备安装数据库为 ...
- MFC CTreeCtrl控件
知识点: 认识CTreeCtrl CTreeCtrl控件属性 CTreeCtrl添加根项 CTreeCtrl添加子项 一.CTreeCtrl控件属性 先设置CTreeCtrl的属性: Has Line ...
- FormData 数据转化为 json 数据
两种方法 <!-- 实例:将 FormData 转化为 json --> <meta charset="utf-8"/> <form enctype= ...
- 小内存VPS apache并发控制参数prefork调优
小内存VPS优化(使用wdcp lnamp一键包安装环境的情况下): 1.主要优化perfork模式下几个参数,防止开启过多的httpd进程占用大量内存导致内存满:在wdcp下修改的httpd配置文件 ...
- 牛客网NOIP赛前集训营-提高组(第八场)-B-推箱子[最短路优化建图]
题意 有 \(n\) 个箱子,指定一个箱子开始向右推,如果碰到了别的箱子会令其移动,问 \(k\) 秒之后每个箱子所在的位置. \(n\leq 10^5\). 分析 转化成最短路模型,如果两个箱子 \ ...
- Unity关于方法事件生命周期官方文档
http://docs.unity3d.com/Manual/ExecutionOrder.html 一.组件运行的基本顺序 下图中创建类的顺序为A,B,C,A1,二运行的结果为A1,B,C,A. 可 ...