YR123 @ 2023-10-02 12:57:08
求助为何RE
#include<bits/stdc++.h>
using namespace std;
int n,sx,sy,ex,ey,ans;
char c[1005][1005];
int fx[]={0,0,1,-1};
int fy[]={1,-1,0,0};
struct Node{
int x,y,cnt;
};
int bfs(){
c[sx][sy]='1';
queue<Node>q;
q.push({sx,sy,0});
while(!q.empty()){
Node h=q.front();
q.pop();
if(h.x==ex&&h.y==ey) return h.cnt;
for(int i=0;i<4;i++){
int tx=h.x+fx[i];
int ty=h.y+fy[i];
if(tx>=1&&tx<=n&&ty>=1&&ty<=n&&c[tx][ty]=='0'){
q.push({tx,ty,h.cnt+1});
c[tx][ty]='1';
}
}
}
return -1;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
c[i][j]=getchar();
}
getchar();
}
cin>>sx>>sy>>ex>>ey;
cout<<bfs();
return 0;
}
by GzkThunder @ 2023-10-02 13:01:46
点击解决(雾)
by YR123 @ 2023-10-02 22:32:22
想明白了,要用cin
此贴结