The problem of the eighth queen is not a real problem of the eighth queen. It is a preliminary condition for this problem: To generate combinations of different rows and columns.
Typedef struct spoint {int X; int y; spoint () {x =-1; y =-1 ;}}; static spoint point [8]; int queen8 (int n, int cur) {static int icount = 0; If (cur = N) {icount ++; For (INT I = 0; I <n; I ++) {printf ("(% d, % d)", point [I]. x, point [I]. y);} printf ("\ n");} else {for (INT I = 0; I <n; I ++) {bool bnextrow = false; for (Int J = 0; j <n; j ++) {int bshow = false; For (int K = 0; k <cur; k ++) {if (I = point [K]. x) {bnextrow = T Rue; break;} If (j = point [K]. y) {bshow = true; break;} If (bnextrow) {bnextrow = false; break;} If (! Bshow) {bshow = false; point [cur]. X = I; point [cur]. y = J; queen8 (A, N, cur + 1) ;}}} return icount;} int wqueen8_train () {int cur = 0; int n = 8; int * B = (int *) malloc (N * sizeof (INT); memset (B, 0, N * sizeof (INT); int num = queen8 (n, cur); Delete [] B; return num ;}
Junior 8 Queen's question