Alternative Eight Queen 's solution.

xiaoxiao2021-03-06  75

The teacher commented on, "garbage", garbage garbage, tube he, anyway, original

//heckboard.h

#pragma overce

Class checkboard {public: checkboard (void); ~ Checkboard (void); private: int * arr, * j1, * j2; public: void arrange (int i); Bool Judge (void); Void Output (Void); private : Int cout; // Record the quantity of the box paid}; // heckboard.cpp

#include "stdafx.h" #include "./heckboard.h"

Checkboard :: Checkboard (Void): cout (0) {Arr = new int =; j1 = new int [15]; j2 = new int [15]; // 8 * 8 Chess pieces in board column Number, the number of rows - the number of columns, there are 15 different results. For (unsigned int i = 0; i <8; i ) {* (Arr i) = i;} // initialize the chessboard, makes only one chess pieces each column}

Checkboard :: ~ Checkboard (void) {delete [] arr; delete [] j1; delete [] j2;

// Chess panel, a co-judgment 8! Saix void checkboard :: arrange (int i) {if (i == 0) {this-> judge (); return;} for (int J = 0; j <= i; j ) {if (j> 0) {if (j% 2) {INT b = * (Arr i); * (Arr i) = * (Arr J-1); * (Arr J -1) = b;} else {INT B = * (Arr i); * (Arr i) = * (Arr Ij); * (Arr Ij) = B;}} Arrange (I-1) ; If ((i 1)% 2) {for (int K = 0; K

// Turn on the checkerboard paving and not ask Bool Checkboard :: Judge (void) {for (int i = 0; i <15; i ) {j1 [i] = 0; J2 [i] = 0;} For (int i = 0; i <8; i ) {IF (j1 [i arr [i]] == 1) Return False; Else J1 [i arr [i]] = 1; if (j2 [7 I-Arr [I]] == 1) Return False; ELSE J2 [7 I-Arr [I]] = 1;} Cout = 1; Output (); Return True;}

// Output Chessboard Layout Void Checkboard :: Output (Void) {for (unsigned INT i = 0; i <8; i ) {Printf ("% D", Arr [i]);} printf ("/ n% d) / N / N / N ", COUT;

/ / Define the entry point of the console application. //

#include "stdafx.h" #include "heckboard.h" INT _TMain (int Argc, _tchar * argv []) {checkboard * pqueen = new checkboard; pqueeen-> arrange (7);

Delete pqueen;

Return 0;}

转载请注明原文地址:https://www.9cbs.com/read-120386.html

New Post(0)