bfs,手贱,vis标记,将y1写成x2,各种改bug
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
using namespace std;
const int maxn = 305;
int vis[ maxn ][ maxn ];
int x1, y1, x2, y2;
struct node{
int x, y, step;
}edge[ maxn * maxn ];
int dir[ 10 ][ 2 ] = { { -2, 1 }, { -2, -1 }, { -1, 2 }, { -1, -2 }, { 1, 2 }, { 1, -2 }, { 2, 1 }, { 2, -1 } };
void Bfs(){
node Q, P, temp;
int s = 0, t = 0;
memset( vis, 0, sizeof( vis ) );
edge[ t ].x = x1;
edge[ t ].y = y1;
edge[ t++ ].step = 0;
vis[ x1 ][ y1 ] = 1;
while( s <= t ){
if( edge[ s ].x == x2 && edge[ s ].y == y2 ){
cout << edge[ s ].step << endl;;
break;
}
for( int i = 0; i < 8; ++i ){
int x0 = edge[ s ].x + dir[ i ][ 0 ];
int y0 = edge[ s ].y + dir[ i ][ 1 ];
if( x0 >= 0 && x0 <= 300 && y0 >= 0 && y0 <= 300 && !vis[ x0 ][ y0 ] ){
vis[ x0 ][ y0 ] = 1;
edge[ t ].step = edge[ s ].step + 1;
edge[ t ].x = x0;
edge[ t++ ].y = y0;
}
}
s++;
}
}
int main(){
while( scanf( "%d%d%d%d", &x1, &y1, &x2, &y2 ) != EOF ){
Bfs();
}
}