This commit is contained in:
Sombit Bose 2020-04-29 22:52:44 +05:30 committed by GitHub
parent e742280a87
commit 0a77b1fd26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,15 +3,15 @@
#define inc_loop(var, start, stop) for (int var=start; var <= stop; var++)
#define dec_loop(var, start, stop) for (int var=start; var >= stop; var--)
void PrintSol(int Board[n][n]) {
inc_loop(i,0,n-1) {
inc_loop(j,0,n-1)
inc_loop(i, 0, n-1) {
inc_loop(j, 0, n-1)
std::cout << Board[i][j] << " ";
std::cout << std::endl;
}
std::cout << std::endl;
if (n%2 == 0 || (n%2 == 1 && Board[n/2+1][0] != 1)){
inc_loop(i,0,n-1){
dec_loop(j,n-1,0)
if (n%2 == 0 || (n%2 == 1 && Board[n/2+1][0] != 1)) {
inc_loop(i, 0, n-1) {
dec_loop(j, n-1, 0)
std::cout << Board[i][j] << " ";
std::cout << std::endl;
}
@ -21,7 +21,7 @@ void PrintSol(int Board[n][n]) {
bool CanIMove(int Board[n][n], int row, int col) {
/// check in the row
inc_loop (i, 0, col-1) {
inc_loop(i, 0, col-1) {
if (Board[row][i] == 1)
return false;
}
@ -43,7 +43,7 @@ void NQueenSol(int Board[n][n], int col) {
PrintSol(Board);
return;
}
inc_loop(i,0,n-1,1) {
inc_loop(i, 0, n-1) {
if (CanIMove(Board, i, col)) {
Board[i][col] = 1;
NQueenSol(Board, col + 1);