题目如下:

我的代码:(老师的)
#include<bits/stdc++.h>
#define to(x,y){vis[x][y]=true;c++;q[++r]={x,y};}
using namespace std;
const int N=1005;
int n,m;
bool vis[N][N],a[N][N];
char ch;
struct T{
int x,y;
}q[N*N],p[N*N];
bool can(int x,int y){
if(a[x-1][y]||a[x+1][y]||a[x][y+1]||a[x][y-1])return false;
return true;
}
bool ok(int x,int y){
if(x<1||x>n||y<1||y>m)return false;
return true;
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>ch;
if(ch=='.')a[i][j]=true;
else a[i][j]=false;
}
}
int ans=1;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(!can(i,j)||a[i][j]||vis[i][j])continue;
int l=1,r=0,c=1,top=0;
r++;
q[r].x=i;
q[r].y=j;
vis[i][j]=true;
while(l<=r){
int x=q[l].x;
int y=q[l].y;
l++;
if(!can(x,y)){
p[++top]={x,y};
continue;
}
if(ok(x-1,y)){
to(x-1,y);
if(ok(x+1,y)){
to(x+1,y);
if(ok(x,y+1)){
to(x,y+1);
if(ok(x,y-1))to(x,y-1);
}
}
}
}
for(int i=1;i<=top;i++)vis[p[i].x][p[i].y]=false;
ans=max(ans,c);
}
}
cout<<ans;
return 0;
}
真服了老师的仁济代码
他写代码从来不检验的