这题输入不是很懂,用字符串直接做有些问题,而每次用字符数组输入然后再将他转化就可以做
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<functional> #include<string> #include<algorithm> #include<iostream> #include<set> #include<vector> #include<queue> #include<cstdlib> using namespace std; const int N=1020; int l[N][N],r[N][N]; int up[N][N]; int f[N][N]; int a[N][N]; int ans1,ans2; int main(){ int i,j,k; int n,m; int t; cin>>t; while(t--){ cin>>n>>m; memset(l,0,sizeof l); memset(up,0,sizeof up); memset(r,0,sizeof r); memset(a,0,sizeof a); for(i=1;i<=n;i++){ for(j=1;j<=m;j++){ char s[5]; scanf("%s",s); if(s[0]=='F'){ a[i][j]=1; l[i][j]=r[i][j]=j; up[i][j]=1; } } } ans1=0; for(i=1;i<=n;i++){ for(j=2;j<=m;j++){ if(a[i][j]==1&&a[i][j-1]==1) l[i][j]=l[i][j-1]; } } for(i=1;i<=n;i++){ for(j=m-1;j>=1;j--){ if(a[i][j]==1&&a[i][j+1]==1) r[i][j]=r[i][j+1]; } } for(i=1;i<=n;i++){ for(j=1;j<=m;j++){ if(i>1&&a[i][j]==1&&a[i-1][j]==1){ up[i][j]=up[i-1][j]+1; l[i][j]=max(l[i][j],l[i-1][j]); r[i][j]=min(r[i][j],r[i-1][j]); } int a=r[i][j]-l[i][j]+1; ans1=max(ans1,3*a*up[i][j]); } } cout<<ans1<<endl; } }