我真服了
这段代码好端端的直接RE了,反反复复,如果把for循环注释掉就好了,求答案
#include<iostream>
#include<queue>
#include<cstring>
#define N 25
using namespace std;
struct node{
int x,y;
};
int Gh[8][2]={{-2,-1},{-2,1},{-1,2},{-1,-2},{1,-2},{2,-1},{2,1},{1,2}};
int Ge[4][2]={{-2,-2},{-2,2},{2,-2},{2,2}};
queue<node>q;
int map[N][N],inq[N][N],u,v;
bool judge(int a,int b){
if(a>20||b>20||a<1||b<1)return 0;
if(inq[a][b]==1)return 0;
return 1;
}
int main(){
node b,w,tp;
cin>>b.x>>b.x>>w.y>>w.y;
/*memset(map,0,sizeof map);
memset(inq,0,sizeof inq);
map[b.x][b.y]=0;
inq[b.x][b.y]=1;
q.push(b);
while(!q.empty()){
tp=q.front();
q.pop();
for(int i=0;i<8;i++){
//马的方式
u=tp.x+Gh[i][0];
v=tp.y+Gh[i][1];
if(judge(u,v)){
inq[u][v]=1;
q.push((node){u,v});
map[u][v]=map[tp.x][tp.y]+1;
}
}
for(int i=0;i<4;i++){
//马的方式
u=tp.x+Ge[i][0];
v=tp.y+Ge[i][1];
if(judge(u,v)){
inq[u][v]=1;
q.push((node){u,v});
map[u][v]=map[tp.x][tp.y]+1;
}
}
}
printf("%d\n",map[1][1]);*/
memset(map,0,sizeof map);
memset(inq,0,sizeof inq);
map[w.x][w.y]=0;
inq[w.x][w.y]=1;
q.push(w);
while(!q.empty()){
tp=q.front();
q.pop();
for(int i=0;i<8;i++){
//马的方式
u=tp.x+Gh[i][0];
v=tp.y+Gh[i][1];
if(judge(u,v)){
inq[u][v]=1;
q.push((node){u,v});
map[u][v]=map[tp.x][tp.y]+1;
}
}
for(int i=0;i<4;i++){
//马的方式
u=tp.x+Ge[i][0];
v=tp.y+Ge[i][1];
if(judge(u,v)){
inq[u][v]=1;
q.push((node){u,v});
map[u][v]=map[tp.x][tp.y]+1;
}
}
}
for(int i=1;i<=20;i++){
//就这个for循环
}
printf("%d\n",map[1][1]);
return 0;
}
}