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 ...
随机推荐
- JAVA框架 Spring 依赖注入
一:介绍 情景:我们在给程序分层的时候:web层.业务层.持久层,各个层之间会有依赖.比如说:业务层和持久层,业务层的代码在调用持久层的时候,传统方式:new 持久层类. 进而进行调用,这种方式会导致 ...
- 分布式计算(一)Ubuntu搭建Hadoop分布式集群
最近准备接触分布式计算,学习分布式计算的技术栈和架构知识.目前的分布式计算方式大致分为两种:离线计算和实时计算.在大数据全家桶中,离线计算的优秀工具当属Hadoop和Spark,而实时计算的杰出代表非 ...
- QT的常用对话框的应用
QMessageBox类提供了常用的弹出式对话框:提示.警告.错误.询问.关于对话框 需要添加头文件 #include <QMessageBox> MESSAGE 是要是显示的字符串 v ...
- iOS VideoToolBox decoder解码失败(-12909和-12911)问题解决
对于任何H.264解码器而言,都要将SPS和PPS信息传递给解码器.FFmpeg内部做了设置,所以没有显示设置.但是对于硬件解码器来讲,开发者必须手动设置.另外,使用FFmpeg解码出来的视频帧是以Y ...
- odoo字段
OpenERP对象字段定义的详解 4 OpenERP对象支持的字段类型有, 基础类型:char, text, boolean, integer, float, date, time, datetime ...
- 搭建HBase的本地模式、伪分布式、全分布式和HA模式
一.安装HBase: 我这里选择的是hbase-1.3.1-bin.tar.gz版本解压HBase: tar -zxvf hbase-1.3.1-bin.tar.gz -C ~/training 配置 ...
- cache-fusion笔记
GRD (global resource directory)保存着所有实例中资源的分布情况 GCS (global cache service)具体执行cache fusion 工作的服务,对应 ...
- 汇编 sub减法指令 比较指令CMP JZ条件跳转指令
二.SUB指令 减法指令SUB (SUBtract) 格式: SUB A,B //A=A-B; 功能: 两个操作数的相减,即从A中减去B,其结果放在A中. 二.CMP 和JZ 指令 比较指令CMP 格 ...
- BZOJ1000-1099板刷计划(附题解链接)
BZOJ1000-1099板刷计划 感觉完全做不动啊... \(Orz\) \(M\_sea\)板刷bzoj狂魔 1000 - 1009 1000 ...懒得说了 1001 懒得平面图转对偶图,最小割 ...
- noi.ac 257 B
链接 题目 区间[l,r]是连续满足,[l,r]中的数字的权值区间是一段连续的.多次询问可以完包含一个区间的连续区间.区间长度尽量小,如果有多个输出左端点靠左的. 分析: [l,r]区间是连续的,当且 ...