#include #include using namespace std; bool isValid(int i,int j, int n,vector,string>>> grid){ if(i>=0 && i=0 && j,string>> getmoves(pair p, int n,vector,string>>> grid){ int i= p.first; int j= p.second; vector,string>> moves(0); if(isValid(i-2, j-1,n,grid)) moves.push_back(make_pair(make_pair(i-2, j-1),"UL")); if(isValid(i-2, j+1,n,grid)) moves.push_back(make_pair(make_pair(i-2, j+1),"UR")); if(isValid(i, j+2,n,grid)) moves.push_back(make_pair(make_pair(i, j+2),"R")); if(isValid(i+2, j+1,n,grid)) moves.push_back(make_pair(make_pair(i+2, j+1),"LR")); if(isValid(i+2, j-1,n,grid)) moves.push_back(make_pair(make_pair(i+2, j-1),"LL")); if(isValid(i, j-2,n,grid)) moves.push_back(make_pair(make_pair(i, j-2),"L")); return moves; } void printShortestPath(int n, int i_start, int j_start, int i_end, int j_end) { // Print the distance along with the sequence of moves. vector,string>>> grid(n,vector,string>>(n)); queue,string>> moves; for(int ii=0; ii,string> b= make_pair(make_pair(-2,-2),"End"); grid[i_start][j_start]=b; int i=1; int k=0; int level=0; while(!moves.empty()) { pair,string> p= moves.front(); moves.pop(); //cout< steps; //steps.push(ss); //cout<< l1 <<"-"<,string>> m= getmoves(p.first, n,grid); for(auto pp:m) { //if(p.first==i_end && p.second==j_end) moves.push(pp); //pp.first.first=p.first.first; // cout<,string> b= make_pair(make_pair(p.first.first,p.first.second),pp.second); grid[pp.first.first][pp.first.second]=b; k++; } if(i==0) { // cout<> n; int i_start; int j_start; int i_end; int j_end; cin >> i_start >> j_start >> i_end >> j_end; printShortestPath(n, i_start, j_start, i_end, j_end); return 0; }