#include #include #include #include //#define DEBUG using namespace std; void knightRecur(vector> &board, int size, int currentX, int currentY, int numOfMoves, int xJump, int yJump) { if(currentX < 0 || currentY < 0 || currentX >= size || currentY >= size) { #ifdef DEBUG cout << "OUT OF RANGE BROKEN " << currentX << " " << currentY << endl; #endif return; } if(numOfMoves >= board[currentX][currentY]) { return; } board[currentX][currentY] = numOfMoves; #ifdef DEBUG cout << "CURRENT X POS: " << currentX << " CURRENT Y POS: " << currentY << " WITH " << numOfMoves << " MOVES" << endl; #endif numOfMoves = numOfMoves + 1; knightRecur(board, size, currentX + xJump, currentY + yJump, numOfMoves, xJump, yJump); knightRecur(board, size, currentX - xJump, currentY + yJump, numOfMoves, xJump, yJump); knightRecur(board, size, currentX + xJump, currentY - yJump, numOfMoves, xJump, yJump); knightRecur(board, size, currentX - xJump, currentY - yJump, numOfMoves, xJump, yJump); knightRecur(board, size, currentX + yJump, currentY + xJump, numOfMoves, xJump, yJump); knightRecur(board, size, currentX - yJump, currentY + xJump, numOfMoves, xJump, yJump); knightRecur(board, size, currentX + yJump, currentY - xJump, numOfMoves, xJump, yJump); knightRecur(board, size, currentX - yJump, currentY - xJump, numOfMoves, xJump, yJump); } int main() { int num; cin >> num; for(int i = 1; i < num; ++i) { for(int j = 1; j < num; ++j) { vector> board(num, vector(num, INT_MAX)); knightRecur(board, num, 0, 0, 0, i, j); int result = board[num - 1][num - 1]; #ifdef DEBUG cout << "NEW RESULT" << endl; #endif if(result == INT_MAX) { cout << "-1 "; } else { cout << result << " "; } } cout << endl; } }