http://ybt.ssoier.cn:8088/problem_show.php?pid=1257 代码:
#include<iostream>
#include<queue>
using namespace std;
int ex,ey;
struct Node{
int x,y;
int sum;
};
queue<Node> q;
char a[301][301];
bool b[301][301];
int xx[]={2,2,1,1,-1,-1,-2,-2};
int yy[]={1,-1,2,-2,2,-2,1,-1};
int n,m;
void bfs(int t_x,int t_y){
cout<<"bfs\n";
q.push({t_x,t_y,1});
b[t_x][t_y]=true;
while(q.size()){
cout<<"d\n";
Node tt=q.front();
if(tt.x==ex&&tt.y==ey){
cout<<"x\n";
cout<<tt.sum<<endl;
break;
}
q.pop();
for(int i=0;i<8;i++){
int temp_x=tt.x+xx[i];
int temp_y=tt.y+yy[i];
if(temp_x>=1&&temp_x<=n&&temp_y>=1&&temp_y<=m&&a[temp_x][temp_y]=='.'&&b[temp_x][temp_y]==0){
b[temp_x][temp_y]=true;
q.push({temp_x,temp_y,tt.sum+1});
}
}
cout<<q.size()<<" "<<tt.x<<" "<<tt.y<<" "<<tt.sum<<endl;
}
}
int main(){
int nn,sx,sy;
cin>>nn;
for(int i=1;i<=nn;i++){
cin>>n;
m=n;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
a[i][j]='.';
}
}
cin>>sx>>sy;
cin>>ex>>ey;
bfs(sx,sy);
}
return 0;
}
希望大佬帮忙看看错哪了