传统弱校HFUT的蒟蒻,真相只有一个

CCF 模拟C 找最大矩形+输入输出外挂

http://115.28.138.223:81/view.page?opid=3

统计出连续的最长乘以当前高度,找最大即可

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define within(x,a,b) ((unsigned)((x)-(a))<=((b)-(a)))
using namespace std;
int readint(int *p)
{
    int ch;
    while(!within(ch=getchar(),'0','9'))
        if(ch == EOF) return EOF;
    int rslt = 0;
    do
        rslt=rslt*10+(ch-'0');
    while(within(ch=getchar(),'0','9'));
    *p = rslt;
    return 1;
}
void out(int a)
{
    if(a>9)
        out(a/10);
    putchar(a%10+'0');
}
int a[1005];
int main()
{
    int x;
    while(cin>>x)
    {
        memset(a,0,sizeof(a));
        int floor=1,max=0,maxfloor=0,looop=0,MAXS=0;
        for(int i=0;i<x;i++)
        {
            readint(&a[i]);
            if(a[i]>maxfloor) {maxfloor=a[i];}
        }
        while(floor<=maxfloor)
        {
            for(int i=0;i<x;i++)
            {
                if(a[i]>=floor)
                {
                    looop++;
                }
                else if(a[i]<floor)
                {
                    if(looop>max) max=looop;
                    looop=0;
                }
                if(looop>max) max=looop;
            }
            int yy=max*floor;
            if(yy>MAXS) MAXS=yy;
            floor++;
            looop=0;
            max=0;
        }
        out(MAXS);
        cout<<endl;
    }
    return 0;
}

 

posted @ 2016-03-28 22:08  未名亚柳  阅读(233)  评论(0编辑  收藏  举报