#include #include #include #include #include #include using namespace std; struct cell { int x, y; int dis; int px,py; cell() {} cell(int x, int y, int dis,int px,int py) : x(x), y(y), dis(dis),px(px),py(py) {} }; bool isInside(int x, int y, int N) { if (x >= 0 && x < N && y >= 0 && y < N) return true; return false; } void minStepToReachTarget(int knightPos[], int targetPos[],int N) { int dx[]={-2,-2,0,2,2,0}; int dy[]={-1,1,2,1,-1,-2}; queue q; q.push(cell(knightPos[0], knightPos[1], 0,-1,-1)); cell t; int x, y,xdif,ydif; bool visit[N ][N ]; cell val[N][N]; for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) { visit[i][j] = false; val[i][j].dis=99; } visit[knightPos[0]][knightPos[1]] = true; while (!q.empty()) { t = q.front(); if(t.dis>(val[t.x][t.y].dis)) { q.pop(); continue; } val[t.x][t.y]=t; q.pop(); visit[t.x][t.y] = true; if (t.x == targetPos[0] && t.y == targetPos[1]) { if(t.dis==-1) cout<<"Impossible"< pp; for(i=0; i=0; i--) { cout<>n; cin>>xs>>ys>>xd>>yd; int knightPos[] = {xs, ys}; int targetPos[] = {xd, yd}; int i; minStepToReachTarget(knightPos, targetPos, n); return 0; }