POJ 2559 Largest Rectangle in a Histogram(单调栈)
2014-05-25 22:27
501 查看
题目链接:POJ 2559 Largest Rectangle in a Histogram
#include <iostream> #include <cstdio> #include <stack> using namespace std; struct Node { int l; long long h; }; int main() { int n; while(scanf("%d", &n), n) { long long h, k = 0, _max = 0; stack <Node> S; Node temp, tmp; for(int i = 0; i < n; i++) { scanf("%lld", &h); temp.l = i, temp.h = h; while(!S.empty() && S.top().h >= h) { tmp = S.top(); S.pop(); k = tmp.h * (i - tmp.l); temp.l = tmp.l; _max = max(_max, k); } S.push(temp); } while(!S.empty()) { tmp = S.top(); S.pop(); k = tmp.h * (n - tmp.l); _max = max(_max, k); } printf("%lld\n", _max); } return 0; }
相关文章推荐
- poj 2559 Largest Rectangle in a Histogram (单调栈)
- poj 2559 Largest Rectangle in a Histogram 求面积最大的矩形(单调栈)
- poj 2559 Largest Rectangle in a Histogram(单调栈)
- (单调栈)poj-2559 Largest Rectangle in a Histogram
- POJ 2559 Largest Rectangle in a Histogram(单调栈)@
- (POJ 2559)Largest Rectangle in a Histogram (POJ 2796) Feel Good(DP、单调栈)
- POJ 2559 Largest Rectangle in a Histogram + POJ 2082Terrible Sets(DP/单调栈)
- POJ 2559 Largest Rectangle in a Histogram(单调栈)
- 文章标题 POJ 2559 : Largest Rectangle in a Histogram (单调栈)
- POJ 2559 Largest Rectangle in a Histogram (单调栈或者dp)
- POJ 2559 Largest Rectangle in a Histogram(单调栈)
- POJ - 2559 Largest Rectangle in a Histogram (单调栈与区间问题)
- POJ 2559 Largest Rectangle in a Histogram(单调栈)
- POJ 2559 Largest Rectangle in a Histogram(单调栈)
- POJ 2559 Largest Rectangle in a Histogram(单调栈维护最大矩形面积)
- 【单调栈】POJ 2559 Largest Rectangle in a Histogram
- POJ 2559 / HDU 1506 / LightOJ 1083 Largest Rectangle in a Histogram (单调栈)
- POJ 2559 Largest Rectangle in a Histogram(单调栈)
- poj 2559 Largest Rectangle in a Histogram(单调栈)
- POJ 2559 Largest Rectangle in a Histogram 单调栈(STL版)