9090
2025-07-30 19:51:57
发布于:广东
#include <bits/stdc++.h>
using namespace std;
int n,m,xx,yy,xxx,yyy,dx[]={1,-1,0,0},dy[]={0,0,1,-1};
char Map[55][55];
bool vis[55][55],flag=false;
struct node{
int x,y,step;
};
queue<node>q;
int main(){
freopen("dawn.in","r",stdin);
freopen("dawn.out","w",stdout);
cin>>n>>m;
for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++){
cin>>Map[i][j];
}
}
cin>>xx>>yy>>xxx>>yyy;
vis[xx][yy]=true;
q.push({xx,yy,0});
while (!q.empty()){
node t=q.front();
q.pop();
if (t.xxxx && t.yyyy){
cout<<t.step;
flag=true;
}
for (int i=0;i<4;i++){
int nx=t.x+dx[i];
int ny=t.y+dy[i];
if (1<=nx && nx<=n && 1<=ny && ny<=m && vis[nx][ny]false && Map[nx][ny]!='#'){
q.push({nx,ny,t.step+1});
vis[nx][ny]=true;
}
}
}
if (flagfalse)cout<<-1;
fclose(stdin);
fclose(stdout);
return 0;
}
这里空空如也
有帮助,赞一个