【POJ】2082
来源:互联网 发布:博优化纤 编辑:程序博客网 时间:2024/06/06 11:01
http://poj.org/problem?id=2082
给一些矩形的宽和高,矩形沿着x轴对齐,求这些矩形组成的连续矩形区域的最大面积。
(1)用栈保存矩形,若高度递增则不断入栈;若当前矩形比栈顶矩形矮,则不断出栈并计算最大面积,直至栈顶矩形比当前矩形矮。
(2)把出栈矩形宽累加得到W,将W和当前矩形宽相加得到当前输入矩形的宽度,入栈。
(3)输入完后若栈不为空,则依次出栈计算最大面积。
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <queue>#include <stack>#include <vector>#include <numeric>#include <algorithm>using namespace std;struct node{ int w,h;};stack <node> s;int n,ans,W;int main(){ while (cin >> n && n!=-1){ ans=0; node tmp; for (int i=0;i<n;i++){ scanf("%d%d",&tmp.w,&tmp.h); if (s.empty()){ s.push(tmp); } else{ W=0; while (!s.empty()&&s.top().h>tmp.h){ W+=s.top().w; ans=max(ans,W*s.top().h); s.pop(); } tmp.w+=W; s.push(tmp); } } W=0; while (!s.empty()){ W+=s.top().w; ans=max(ans,W*s.top().h); s.pop(); } cout << ans << endl; }}
阅读全文
0 0
- POJ 2082
- POJ 2082
- POJ-2082
- 【POJ】2082
- POJ 2082
- POJ 2082 Terrible Sets
- poj 2082 Terrible Sets
- POJ 2082 Terrible Sets
- POJ 2082 堆栈
- POJ 2082 Terrible Sets
- POJ 2082Terrible Sets
- poj 2082 Terrible Sets
- POJ 2082 Terrible Sets
- POJ 2082 Terrible Sets
- poj 2082 Terrible Sets
- POJ 2082Lost Cows<>
- poj 2082 Terrible Sets
- POJ 2082 Terrible Sets
- 集合
- 好玩的数学问题
- linux timerfd_create说明简单翻译
- CentOS 7添加第三方源列表
- WOJ-419 无聊的游戏
- 【POJ】2082
- apache 目录级的URL重写支持
- 在Eclipse中测试MySQL-JDBC(7)JDBC工具(JdbcUtil)类抽取 再优化
- RecyclerView 的使用流程
- 单例模式|设计模式
- 识更加强大的滚动控件——RecyclerView
- 流形上的预积分
- spi
- Jenkins 钉钉 机器人 Python版本