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框架:hibernate(四)
一.绑定本地session 原理:之前connection实现事务一个道理,2种方法:1.变量下传.2.因为servlet是单线程,和本地当前线程绑定. 配置: 1)配置核心配置文件hibernate ...
- kubespray -- 快速部署高可用k8s集群 + 扩容节点 scale.yaml
主机 系统版本 配置 ip Mater.Node,ansible CentOS 7.2 4 ...
- Eclipse-设置格式化代码时不格式化注释
在Eclipse里设置格式化代码时不格式化注释 今天格式化代码 发现直接format会把注释也一块格式化了,有时候会把好好的注释弄的很乱.甚为头疼. 查阅之后解决办法如下: Windows -> ...
- 创世纪 BZOJ3037 & [Poi2004]SZP BZOJ2068
分析: 树形DP中的一种,基环树DP 针对每一个环跑DP,f[i],g[i]分别表示选或者不选,之后我们注意每次遍历的时候,不要重复遍历. 附上代码: #include <cstdio> ...
- struts2_文件上传的功能
使用Struts内置的fileUpload拦截器(已默认配置)即可,设计的电商网站,提供用户头像上传的功能 1. 2. 3. 4. 5. 5.未使用拦截器 6.未使用filename 7. 8. 9.
- 20155307《网络对抗》MSF基础应用
实验过程 实验系统 所需设备: 靶机1:Windows XP Professional SP2 ,IP地址:192.168.1.128 靶机2:Windows XP Professional SP3 ...
- 《网络对抗》Exp7 网络欺诈防范
20155336<网络对抗>Exp7 网络欺诈防范 实验内容 本实践的目标理解常用网络欺诈背后的原理,以提高防范意识,并提出具体防范方法.具体实践有 简单应用SET工具建立冒名网站 (1分 ...
- noip 提高组 2010
T1:机器翻译 题目背景 小晨的电脑上安装了一个机器翻译软件,他经常用这个软件来翻译英语文章. 题目描述 这个翻译软件的原理很简单,它只是从头到尾,依次将每个英文单词用对应的中文含义来替换.对于每个英 ...
- R语言学习 第一篇:变量和向量
R是向量化的语言,最突出的特点是对向量的运算不需要显式编写循环语句,它会自动地应用于向量的每一个元素.对象是R中存储数据的数据结构,存储在内存中,通过名称或符号访问.对象的名称由大小写字母.数字0-9 ...
- Merge:解析on子句和when not match子句的陷阱
在细节上,体现编程的修养.每一位大师,master,其基础必定夯实.废话不多说,直接上干货,Merge子句用于对两个数据表执行数据同步,On子句指定匹配(when matched)条件,When子句指 ...