#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //generate all possible unique destinations from (0,0) in an integer no of steps //stop once no new unique destination can be obtained this will be at some step k //there are a max of n^2 unique destinations, since we only generate new destinations at each level of tree //k is guaranteed to be finite using namespace std; int getMinSteps(int a, int b, int n){ //bool hasBeenDiscovered[n][n]; std::vector> hasBeenDiscovered(n,std::vector(n, false)); int minSteps=-1,x=0,y=0,currentLevel=1; pair currentNode; pair lastNodeCopyInCurrentLevel,endOfQueue; queue> nextNodesInBFS;//stores the coordinates of the next node as we traverse the tree BFS style int TotalReachableNodes=1; //possible displacements (deltax, deltay); std::pair * displacements=new pair[8]; displacements[0]=make_pair(a,b); displacements[1]=make_pair(a,-b); displacements[2]=make_pair(-a,b); displacements[3]=make_pair(-a,-b); displacements[4]=make_pair(b,a); displacements[5]=make_pair(b,-a); displacements[6]=make_pair(-b,a); displacements[7]=make_pair(-b,-a); //initialise queue for(int i=0;i!=8;i++){ int x2=x+displacements[i].first,y2=y+displacements[i].second; if(x2>=0 && x2=0 && y2=0 && x2=0 && y2> n; int results[n-1][n-1]={0}; for(int a=1;a!=n;a++){ for(int b=temp;b!=n;b++){ int minSteps=getMinSteps(a,b,n); results[a-1][b-1]=minSteps; if(a!=b) results[b-1][a-1]=minSteps;//(a,b) & (b,a) result in the same possible moves from any source } ++temp; } //print results for(int i=0;i!=n-1;i++){ for(int j=0;j!=n-1;j++) { const char endChar=(j==n-2)?'\n':' '; cout<