一.题目链接:

POJ-2559

二.题目大意:

有 n 个长方形排在一条线上,宽均为 1 ,给出每个矩形的高度.

用一个长方形木板截取,求截得的最大面积.

三.分析:

***题,分析个毛,单调栈入门题.

好的,就这样.

四.代码实现:

#include <set>
#include <map>
#include <ctime>
#include <queue>
#include <cmath>
#include <stack>
#include <vector>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define eps 1e-6
#define pi acos(-1.0)
#define ll long long int
using namespace std;
const int M = (int)1e5;
const ll mod = (ll)1e9 + 7;
const ll inf = 0x3f3f3f3f3f;

ll height[M + 5];
ll st[M + 5];
ll width[M + 5];

int main()
{
    int n;
    while(~scanf("%d", &n) && n)
    {
        for(int i = 1; i <= n; ++i)
            scanf("%lld", &height[i]);
        height[n + 1] = 0;
        ll ans = 0;
        int top = 0;
        for(int i = 1; i <= n + 1; ++i)
        {
            if(height[i] > st[top])
            {
                st[++top] = height[i];
                width[top] = 1;
            }
            else
            {
                int w = 0;
                while(height[i] < st[top])
                {
                    w += width[top];
                    ans = max(ans, st[top] * w);
                    top--;
                }
                st[++top] = height[i];
                width[top] = w + 1;
            }
        }
        printf("%lld\n", ans);
    }
    return 0;
}