hdu1505

the main algorithm as the 1506

#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
char gird[1100][1100];
int  num[1100][1100];
int m,n;
int find(int a){
    int i,j,res,max;
    int t;
    int l[1100],r[1100];
    l[1]=1; r[m]=m;
    for(i=2;i<=m;++i){
        t=i;
        if(num[a][i]==0){
            l[i]=i;
            continue;
        }
        while(t>1&&num[a][i]<=num[a][t-1])
            t=l[t-1];
        l[i]=t;
    }
    for(i=m-1;i>=1;--i){
        t=i;
        if(num[a][i]==0){
            r[i]=i;
            continue;
        }
        while(t<m&&num[a][i]<=num[a][t+1])
            t=r[t+1];
        r[i]=t;
    }
    res=0;
    for(i=1;i<=m;++i){
        if( (r[i]-l[i]+1)*3*num[a][i] > res )
            res = (r[i]-l[i]+1)*3*num[a][i];
    }

    /*
    for(i=1;i<=m;++i)
        cout<<num[a][i]<<" ";
    cout<<endl;
    cout<<"left-----"<<endl;
    for(i=1;i<=m;++i)
        cout<<l[i]<<" ";
    cout<<endl;
    cout<<"right---"<<endl;
    for(i=1;i<=m;++i)
        cout<<r[i]<<" ";
    cout<<endl;
    cout<<res<<endl;

    */

    return res;
}
int init(){
    cin>>n>>m;
    int i,j,tmp;
    for(i=1;i<=n;++i)
        for(j=1;j<=m;++j)
            cin>>gird[i][j];
    for(j=1;j<=m;++j)
        if(gird[1][j]=='F') num[1][j]=1;
        else                num[1][j]=0;
    for(i=2;i<=n;++i)
        for(j=1;j<=m;++j){
            if(gird[i][j]=='F') num[i][j]=num[i-1][j]+1;
            else                  num[i][j]=0;
        }
    int res=0;
    for(i=1;i<=n;++i){
        tmp=find(i);
        if(tmp>res) res=tmp;
    }
    return res;
}
int main(){
    int t,i,j;
    while(cin>>t){
        while(t--){
            cout<<init()<<endl;
        }
    }
    return 0;
}

            

 

 

posted on 2013-11-17 14:38 symons 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/symons1992/p/3427832.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值