poj2559
来源:互联网 发布:淘宝联盟社区找淘宝客 编辑:程序博客网 时间:2024/06/06 09:42
【题意】
给定n个立方体的高度,求最大矩形面积
【输入】
多组数据,数据以单独一行一个0结束
每组数据一行,第一个数字为n,接下来n个数字表示个立方体的高度
【输出】
对于每组数据,输出一个数表示最大矩形面积
单调栈
从左到右从右到左扫描两次,出栈的时候计算最大面积
很不幸的wa,思路不够全面
program poj2559;var tot,n,i,j,k,s,e:longint; now,ans:int64; h,stack:array [0..100001] of int64;begin repeat read(n); if n=0 then break; for i:=1 to n do read(h[i]); ans:=0; h[n+1]:=0; h[0]:=0;; tot:=0; stack[0]:=0; for i:=1 to n+1 do if h[i]>h[stack[tot]] then begin inc(tot); stack[tot]:=i end else begin now:=tot; while h[stack[now]]>h[i] do dec(now); for k:=now+1 to tot do if ans<h[stack[k]]*(stack[tot]-stack[k-1]) then ans:=h[stack[k]]*(stack[tot]-stack[k-1]); tot:=now; inc(tot); stack[tot]:=i; end; tot:=0; stack[0]:=n+1; for i:=n downto 0 do if h[i]>h[stack[tot]] then begin inc(tot); stack[tot]:=i end else begin now:=tot; while h[stack[now]]>h[i] do dec(now); for k:=now+1 to tot do if ans<h[stack[k]]*(stack[k-1]-stack[tot]) then ans:=h[stack[k]]*(stack[k-1]-stack[tot]); tot:=now; inc(tot); stack[tot]:=i; end; writeln(ans); until false;end.
- poj2559
- poj2559
- POJ2559
- POJ2559.md
- POJ2559 最大矩形面积
- 栈的运用-poj2559
- poj2559模拟单调栈
- poj2559栈应用
- poj2559单调栈
- POJ2559 单调队列
- POJ2559 最大矩形面积
- poj2559(单调栈)
- POJ2559单调栈
- POJ2559 Largest Rectangle in a Histogram(DP)
- poj2559 我要做的足够 强大
- 萌萌的单调栈 : poj2796 , poj2559 ,
- poj2559 Largest Rectangle in a Histogram
- poj2559 Largest Rectangle in a Histogram
- 内联函数
- 定制centos6.0
- Asp.net连接Excel字符串
- VB.Net 中 WithEvents、AddHandler
- 提升本程序进程优先级和权限(VC++源代码) (转)
- poj2559
- Source Insight宏 - CppUnit单元测试框架自动生成
- 详解网络数字电视的实现方法与关键技术
- CentOS 6.2 Rhytembox mp3
- 学习一门新的php框架的方法
- 数据库主键和外键设计的原则
- windows7(32位)+vs2010+freeglut2.8.0
- asp.net RDLC 部署总结 windows server 2008 r2
- 从10.2.0.1升级到10.2.0.4出现问题ORA-12514:TNS:监听程序当前无法识别连接描述符中请求的服务