In fact, it was a bit interesting to see a blogger who wrote a note on the subject yesterday, the day before yesterday. He wanted to write it on his own.
In fact, I found that the above student wrote
Place eight queens on chess so that they cannot attack each other. That is to say, neither of the two queens can be in the same row, column, or diagonal line.
Extend
A two-dimensional array seems to be used. Not required. One-dimensional array, for example
There are a lot of ways to implement this idea on the Internet, including those mentioned above, so don't worry about whether there are any improvements or not. You can just exercise it once.
The code is good. I think there is nothing to say about recursive methods. It is easy to understand the space. Write non-recursive implementations when you are free tomorrow.
#include<iostream><fstream><iomanip><stdlib.h> Check( rowCurrent, *&NQueen); Print(ofstream &os, n, *&NQueen); Solve( rowCurrent, *&NQueen, n, &count, ofstream &os); Check( rowCurrent, *& i = (i <(NQueen[i] == NQueen[rowCurrent] || (abs(NQueen[i]-NQueen[rowCurrent]) == abs(i- ++ Print(ofstream &os, n, *&<< ( i = ;i < n;i++( j = ; j < n; j++<<(NQueen[i]==j?:<<setw(<<<< Solve( rowCurrent, *&NQueen, n, &count, ofstream &(rowCurrent == n) ++( i = ; i < n; i++= i; +,NQueen,n,count,os); n; count = ; cout<<<<>>(n<<<<< *NQueen = <<<<count<<<<
By the way, we will give the casual address of the student mentioned above:
Http://www.cnblogs.com/FZQL/p/3485616.html