• CCF_ 201312-3_最大的矩形


    遍历数组中每一元素,左右延伸得出宽度。

    #include<iostream>
    #include<cstdio>
    using namespace std;
    
    int main()
    {
        int n,a[1005],sum = 0;
        cin >> n;
        for(int i = 1;i <= n;i++)    cin >> a[i];
        for(int i = 1;i <= n;i++)
        {
            int j,left = -1,right = -1;
            for(j = i-1;j > 0;j--)
            {
                if(a[j] < a[i])
                {
                    left = j;
                    break;
                }
            }
            if(left == -1)    left = 0;
            for(j = i+1;j <= n;j++)
            {
                if(a[j] < a[i])
                {
                    right = j;
                    break;
                }
            }
            if(right == -1)    right =    n+1;
            sum = max(sum,(right-left-1)*a[i]);
        }
        cout << sum << endl;
        return 0;
    }
  • 相关阅读:
    [LeetCode] 240
    [LeetCode] 169
    [LeetCode] 28
    [LeetCode] 27
    [LeetCode] 14
    [LeetCode] 9
    [LeetCode] 7
    [LeetCode] 2
    数据库开发规范
    Mysql优化
  • 原文地址:https://www.cnblogs.com/zhurb/p/5844283.html
Copyright © 2020-2023  润新知