Lovely_ChongYun @ 2022-06-19 20:08:06
#include<bits/stdc++.h>
using namespace std;
int n;
int dx[4]={0,1,0,-1};
int dy[4]={-1,0,1,0};
char a[2222][2222];
struct node{
int x,y,step;
}q[100010];
int head=0;
int tail=0;
int main(){
int y1;
int x1;
int x2;
int y2;
cin>>n;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cin>>a[i][j];
}
}
cin>>x1>>y1>>x2>>y2;
q[tail].x=x1;
q[tail++].y=y1;
a[x1][y1]='1';
while(head<=tail){
for(int i=0;i<=3;i++){
int nx=q[head].x+dx[i];
int ny=q[head].y+dy[i];
if(nx>=1&&nx<=n&&ny>=1&&ny<=n&&a[nx][ny]!='1'){
if(nx==x2&&ny==y2){
cout<<q[head].step+1;
return 0;
}
a[nx][ny]='1';
q[tail].x=nx;
q[tail].y=ny;
q[tail++].step=q[head].step+1;
}
}
head++;
}
cout<<'0';
return 0;
}
by _DeadPig_ @ 2022-06-19 20:11:33
标签可以给你思路=)
by Usada_Pekora @ 2022-06-19 20:33:59
@caozerui0521
q
开小了,最大是
队列储存方式有问题,虽然这样也能通过这题。
by Lovely_ChongYun @ 2022-06-19 20:58:28
@Zyingyzzz
@Ygboss
谢谢了
by _ChongYun_ @ 2022-06-19 21:02:07
听我说谢谢你~
by _ChongYun_ @ 2022-06-19 21:04:37
咦?怎么没对(这是我另一个号)
by _ChongYun_ @ 2022-06-19 21:08:11
@Zyingyzzz
哦哦,是我还开小了,打扰了抱歉,已AC