hdu 1505 City Game (hdu1506加强版)

# include <stdio.h>
# include <algorithm>
# include <string.h>
# include <iostream>
using namespace std;
char a[1010][1010];
int dd[1010][1010];///宽度
int r[1010],l[1010];
int main()
{
    int t,i,j,n,m,max1;
    while(~scanf("%d",&t))
    {
        while(t--)
        {
            scanf("%d%d",&n,&m);
            getchar();
            for(i=1; i<=n; i++)
                for(j=1; j<=m; j++)
                    cin>>a[i][j];
            for(i=1; i<=m; i++)
                dd[0][i]=0;///初始化虚设的一行

            for(i=1; i<=n; i++) ///求出每点高度
            {
                for(j=1; j<=m; j++)
                {
                    if(a[i][j]=='F')
                        dd[i][j]=dd[i-1][j]+1;
                    else
                        dd[i][j]=0;
                }
            }
            max1=-1;
            for(i=1; i<=n; i++)///转化为hdu1506
            {
                for(j=1; j<=m; j++)
                    l[j]=r[j]=j;
                for(j=2; j<=m; j++)
                {
                   while(dd[i][l[j]-1]>=dd[i][j]&&l[j]>1)
                     l[j]=l[l[j]-1];
                }
                for(j=m-1; j>=1; j--)
                {
                   while(dd[i][r[j]+1]>=dd[i][j]&&r[j]<m)
                     r[j]=r[r[j]+1];
                }
                for(j=1; j<=m; j++)
                {
                    max1=max(max1,dd[i][j]*(r[j]-l[j]+1));
                }
            }
            printf("%d\n",max1*3);
        }
    }
    return 0;
}

posted @ 2016-04-10 10:10  mengfanrong  阅读(150)  评论(0编辑  收藏  举报