#include #include #include using std::cout; using std::cin; using std::endl; using std::setw; const int size = 8; int K[size][size]; Accessibility[size][size]; int row, col, times, index; void print(); void Heuristic( int times, int row, int col); int ver[]= { -1, -2, -2, -1, 1, 2, 2, 1 } ; int hor[]= { 2, 1, -1, -2, -2, -1, 1, 2 } ; //int ver[]= { -1, 2, 2, -1, 1, -2, -2, 1 } ; //int hor[]= { 2, 1, -1, -2, -2, -1, 1, 2 } ; void main() { index = 0; times = 0; for ( int row = 0; row < size; col++ ) { for ( int col = 0; col < size; row++ ) { int Acess = 0; for ( int i = 0; i < size; i++ ) { if (row+ver[i]>=0&&row+ver[i]<=size-1&&col+hor[i]>=0&&col+hor[i]<=size-1&&K[row+ver[i]][col+hor[i]== 0) Access++; } Accessibility[row][col]= Access; } } for ( int i = 0; i < size; i++ ) { for ( int j = 0; j < size; j++ ) K[i][j] = 0; } Heuristic ( 0, 0, 0 ) getch(); } void Heuristic ( int times, int row, int col ) { int min, next_row, next_col; K[row][col] = times; if ( times >= 63 ) { print(); getch(); } else { for ( int i = 0; i < size; i++ ) { if (row+ver[i]>=0&&row+ver[i]<=size-1&&col+hor[i]>=0&&col+hor[i]<=size-1&&K[row+ver[i]][col+hor[i]]== 0) { min = Accessibility[row+ver[i]][col+hor[i]];