用的BFS,样例过不了,改动一点就不能输出,有没有大佬帮忙看看怎么改
by Alvacy @ 2024-02-03 16:28:25
把
```cpp
qx.push(x);
qx.push(y);
```
改成
```cpp
qx.push(x);
qy.push(y);
```
试试
by cabbage_flower @ 2024-02-03 16:43:00
```cpp
#include<bits/stdc++.h>
using namespace std;
int step[405][405];
int dx[8]{1,2,2,1,-1,-2,-2,-1},dy[8]{2,1,-1,-2,-2,-1,1,2};
int main(){
int n,m,x,y;
cin >> n >> m >> x >> y ;
memset(step,-1,sizeof(step));
step[x][y]=0;
queue <int> qx;
queue <int> qy;
qx.push(x);
qy.push(y);//这里
while(!qx.empty()){
x=qx.front();
y=qy.front();
qx.pop();
qy.pop();
for(int i=0;i<8;i++){
int xx=x+dx[i];
int yy=y+dy[i];//这里
if( xx>=1 && yy>=1 && xx<=n && yy<=m && step[xx][yy]==-1){//这里整个图是 1到n 和 1到m 的图
step[xx][yy]=step[x][y]+1;
qx.push(xx);
qy.push(yy);
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
printf("%-5d",step[i][j]);
}
cout << endl;
}
}
```
by sad_lin @ 2024-02-03 16:45:38
@[Alvacy](/user/1081501) 改动后AC记录
[P1443](https://www.luogu.com.cn/record/145969167)
by sad_lin @ 2024-02-03 16:46:42
@[sad_lin](/user/1057821) AC了,已关,感谢!
by Alvacy @ 2024-02-03 17:08:25
@[jinmingkai](/user/757954) 感谢,已关
by Alvacy @ 2024-02-03 17:10:25
现在AC了,此帖封楼了哈
by Alvacy @ 2024-02-03 17:11:03