wocwssb找到原因了我先调一下
by a2lyaXNhbWUgbWFyaXNh @ 2022-10-07 12:05:18
还是死循环qwq
```
#include<bits/stdc++.h>
using namespace std;
int sx,sy,ex,ey,n,m;
bool g[2010][2010];
bool vis[2010][2010];
int step[2010][2010];
char tmp;
void bfs();
short dx[]=
{1,0,-1,0},
dy[]=
{0,-1,0,1};
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
cin>>tmp;
if(tmp=='#')g[i][j]=1;
else if(tmp=='d')ex=i,ey=j;
else if(tmp=='m')sx=i,sy=j;
}
bfs();
if(step[ex][ey])cout<<step[ex][ey];
else cout<<"No Way!";
return 0;
}
void bfs(){
queue<pair<int,int> >q;
q.push(make_pair(sx,sy));
vis[sx][sy]=1;
step[sx][sy]=0;
while(q.size()){
int x=q.front().first;
int y=q.front().second;
for(int i=0;i<4;i++){
int xx=
x+dx[i],
yy=
y+dy[i];
if(xx>=1 and xx<=n and yy>=1 and yy<=m and
not vis[xx][yy] and not g[xx][yy]){
step[xx][yy]=step[x][y]+1;
q.push(make_pair(xx,yy));
if(xx==ex and yy==ey)
return;
}
}
}
}
```
by a2lyaXNhbWUgbWFyaXNh @ 2022-10-07 12:06:42
没出队
by unsigned_short_int @ 2022-10-07 12:15:06
@[S__B](/user/661595)
by unsigned_short_int @ 2022-10-07 12:17:08
楼上正解
by CarroT1212 @ 2022-10-07 12:44:23
@[CarroT1212](/user/319803) woc没发现wssb
by a2lyaXNhbWUgbWFyaXNh @ 2022-10-07 12:50:24