标签:
题意:给出n个宽度为1 高度为hi的长方形
问能圈出的最大长方形面积多大
思路:http://blog.csdn.net/dgq8211/article/details/7740610
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<stack> using namespace std; #define ll __int64 struct Node { int wid; ll hi; ll s; }; Node node[100000+1000]; int main() { int n,h; int i,j,k; int l,r; while(scanf("%d",&n),n) { stack<Node> q; ll maxx=0; Node now; now.hi=-1; now.wid=0; q.push(now); for(i=0;i<=n;i++) { //printf("%d\n",i); if(i!=n) scanf("%d",&h); else h=0; if(h>q.top().hi) { now.hi=h; now.wid=1; q.push(now); } else { int cnt=0; while(q.top().hi>=h) { now=q.top(); q.pop(); maxx=max(maxx,(cnt+now.wid)*now.hi); cnt+=now.wid; } now.wid=cnt+1; now.hi=h; q.push(now); } } printf("%I64d\n",maxx); } return 0; }
hdu 1506 Largest Rectangle in a Histogram(单调栈)
标签:
原文地址:http://www.cnblogs.com/sola1994/p/4396024.html