Once upon a time, there was an emperor who had eight queens, which resulted in a series of messy problems. Haha
Joke ~~~~
The eight queens issue is an ancient and famous issue and is a typical case of backtracking algorithms. This problem was raised by the international chess player Max besell in 1848: Eight queens were placed on 8x8 gags of chess, so that they could not attack each other, that is to say, neither of the two queens can be in the same row, column, or diagonal line. Gaussian believes there are 76 solutions. In 1854, different authors published 40 different solutions in the Berlin chess magazine. Later, they used Graph Theory to solve 92 solutions. After the computer is invented, there are multiple ways to solve this problem.
Specific algorithms:
# Include "stdafx. h" # include
# Define N 8 typedef struct _ tag_Pos {int ios; int jos;} Pos; static char board [N + 2] [N + 2]; static Pos [] ={{-1,-1 },{-1, 0 },{-1, 1 }}; static int count = 0; void init () {int I = 0; int j = 0; for (I = 0; I
N) {count ++; printf ("Solution: % d \ n", count); display (); getchar () ;}else {for (j = 1; j <= N; j ++) {if (check (I, j) {board [I] [j] = '*'; find (I + 1 ); board [I] [j] = '';}}} int main () {init (); find (1); system (" pause "); return 0 ;}
Result: a total of 92 solutions are provided for the eight queens, which are not listed here.
For more information, see your running results ~~~~~