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 ...
随机推荐
- Android 多用户多缓存的简单处理方案
需求:1.在缓存中记录用户登录信息.例如:用户名,密码 2.记录用户操作数据.例如:是否记住用户名密码.设置7天内自动登录等 简单设计:1)使用sqlite设计一张用户数据表,有用户名.密码.操作数据 ...
- excel的宏与VBA入门(二)——数据类型与变量
一.属性与方法 1.属性 上面单击对象,下面即显示对应的属性: 2.方法 双击左上的对象,即可看到相应的方法: 二.数据类型 到 Boolean True 或 False , 到 , ,,, 到 ,, ...
- 20155320 Exp9 Web安全基础
20155320 Exp9 Web安全基础 [实验后回答问题] (1)SQL注入攻击原理,如何防御 SQL注入攻击就是通过把SQL命令插入到Web表单递交或输入域名或页面请求的查询字符串,最终达到欺骗 ...
- 字典学习(Dictionary Learning, KSVD)详解
注:字典学习也是一种数据降维的方法,这里我用到SVD的知识,对SVD不太理解的地方,可以看看这篇博客:<SVD(奇异值分解)小结 >. 1.字典学习思想 字典学习的思想应该源来实际生活中的 ...
- Android开发——Android多进程以及使用场景介绍
个层级,具体可以查看Android开发--Android进程保活招式大全中1.1部分的内容,这里就不赘述了. 根据进程中当前活动组件的重要程度,Android 会将进程评定为它可能达到的最高级别.例如 ...
- [CTSC2006]歌唱王国
[CTSC2006]歌唱王国 Tags:题解 题意 链接:在空串后不断随机添加字符,直到出现串\(S_i\)为止.求最终串的期望长度.\(\sum |S_i|\le 5*10^6\) 题解 以下内容来 ...
- wordpress必装的插件 wp最常用的十个插件
wordpress是世界上著名的博客系统,简称wp.一般新安装完wordpress以后,往往需要首先安装一些插件,这样才可以使用wordpress的更多功能.wp最常用的十个插件有哪些呢,可能根据每个 ...
- 微信小程序 Echarts 异步数据更新
微信小程序 Echarts 异步数据更新的练习,被坑了很多次,特作记录. 作者:罗兵 地址:https://www.cnblogs.com/hhh5460/p/9989805.html 0.效果图 ...
- Hadoop日记Day16---命令行运行MapReduce程序
一.代码编写 1.1 单词统计 回顾我们以前单词统计的例子,如代码1.1所示. package counter; import java.net.URI; import org.apache.hado ...
- Codeforces 950D A Leapfrog in the Array (思维)
题目链接:A Leapfrog in the Array 题意:给出1-n的n个数,从小到大每隔一个位置放一个数.现在从大到小把数往前移动,每次把最右边的数移动最靠右边的空格处直到n个数都在前n个位置 ...