我的代码:
#include<bits/stdc++.h>
using namespace std;
int n,m;
char a[1005][1005];
int step[1005][1005];
int maxn=-1;
struct node{
int x,y;
};
void init()
{
memset(step,0,sizeof a);
}
int main()
{
cin >> n >> m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin >> a[i][j];
}
}
for(int x=1;x<=n;x++)
{
for(int y=1;y<=n;y++)
{
if(a[x][y]!='.') continue;
init();
step[x][y]=1;
queue<node> que;
que.push((node){x,y});
while(!que.empty())
{
node now=que.front();
que.pop();
maxn=max(maxn,step[now.x][now.y]);
int dx[15]={11451,0,0,-1,1};
int dy[15]={10086,1,-1,0,0};
for(int i=1;i<=4;i++)
{
int xx=now.x+dx[i];
int yy=now.y+dy[i];
if(xx<1||xx>n||yy<1||yy>m) continue;
if(a[xx][yy]=='#') continue;
if(step[xx][yy]) continue;
step[xx][yy]=step[now.x][now.y]+1;
que.push((node){xx,yy});
}
}
}
}
cout << maxn-1;
return 0;
}
能够AC,但是调了很久,最开始我写的28行是
if(a[x][y]=='#') continue;
就莫名其妙错了,但是改成
if(a[x][y]!='.') continue;
就离奇的AC了,这是什么原理?!!!求大神帮助蒟蒻 333