0分求助

P1746 离开中山路

代码给你改好了 ```cpp #include<bits/stdc++.h> using namespace std; char a[1005][1005]; bool vis[1005][1005]; int n,m,startx,starty,endx,endy; struct node{ int x,y,cnt; }b,c; int dir[4][2]={{-1,0},{0,1},{1,0},{0,-1}}; queue<node> q; void bfs(int t,int u){ q.push({t,u,0}); vis[t][u]=1; while(!q.empty()){ c=q.front(); q.pop(); for(int i=0;i<4;i++){ int dx=c.x+dir[i][0]; int dy=c.y+dir[i][1]; if(dx>=1&&dx<=n&&dy>=1&&dy<=n&&vis[dx][dy]==0&&a[dx][dy]=='0'){ vis[dx][dy]=1; if(dx==endx&&dy==endy){ cout<<c.cnt+1<<endl; return; } b.x=dx; b.y=dy; b.cnt=c.cnt+1; q.push(b); } } } return; } int main(){ cin>>n; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ cin>>a[i][j]; } } cin>>startx>>starty>>endx>>endy; bfs(startx,starty); return 0; } ```
by wangzhongqian @ 2024-05-08 20:40:54


@[C_Boa](/user/1022472)
by wangzhongqian @ 2024-05-08 20:41:11


求关(逃
by wangzhongqian @ 2024-05-08 20:41:42


@[wangzhongqian](/user/1298242) OKOK 已关注
by C_Boa @ 2024-05-10 12:03:56


|