#include #include #include #include #include #include #include using namespace std; int results[25][25] = { 0 }; int get_result(int a, int b, int n, std::array, 8> const & moves) { int steps[25][25] = { 0 }; steps[0][0] = 1; std::queue> Q; Q.push(std::make_pair(0, 0)); while(!Q.empty()) { auto p = Q.front(); Q.pop(); if (p.first == n - 1 && p.second == n - 1) { return steps[p.first][p.second]; } for(auto m: moves) { int newI = p.first + m.first; int newJ = p.second + m.second; if (newI >= 0 && newI < n && newJ >= 0 && newJ < n) { int& step = steps[newI][newJ]; if (step == 0) { step = steps[p.first][p.second] + 1; Q.push(std::make_pair(newI, newJ)); } } } } return 0; } int main() { int n; cin >> n; for (size_t i{1}; i < n; i++) { for (size_t j{i}; j < n; j++) { std::array, 8> moves { std::make_pair(i, j), std::make_pair(-i, j), std::make_pair(-i, -j), std::make_pair(i, -j), std::make_pair(j, i), std::make_pair(-j, i), std::make_pair(-j, -i), std::make_pair(j, -i), }; results[i-1][j-1] = get_result(i-1, j-1, n, moves) - 1; } } for (size_t i{0}; i < n -1 ; i++) { for (size_t j{0}; j < n-1; j++) { if (j >= i) { cout << results[i][j] << " "; } else { cout << results[j][i] << " "; } } cout << endl; } /* Enter your code here. Read input from STDIN. Print output to STDOUT */ return 0; }