-->
当前位置:首页 > 题库

PROGRAMMING:Eight queens problem

Luz5年前 (2021-05-10)题库503
In chess, the queen is the most powerful piece. She can walk horizontally, straightly and obliquely. In 1848, chess player Max Bessel put forward the famous eight queens problem, that is, in August × Eight queens are placed on the chessboard of 8, so that they cannot attack each other - that is, no two Queens can be in the same row, column or diagonal line. For example:




![ Title. JPG] (~ / f02577b2-a28e-4f3b-bbc7-93801a88a630. JPG)

Now let's extend the chessboard to $$n times n $, and put $$n $$queens on the chessboard. How do you put them?
Please write a program, input a positive integer $$n $$, output all the pendulum (chessboard grid blank space shows the period ".", Queen show the letter "Q", every two characters between a space).
####Input format
>Positive integer $$n (n > 0)$$
####Output format
>If the problem has a solution, output all the pendulum methods (one line between each two pendulum methods).
>If the problem has no solution, output none.
Requirements: the trial sequence is from top to bottom, and each line is from left to right. Please refer to output example 2.
####Input sample 1
```in
three
```
####Output sample 1
```out
None
```
####Input sample 2
```in
six
```
####Output sample 2
```out
. Q . . . .
. . . Q . .
. . . . . Q
Q . . . . .
. . Q . . .
. . . . Q .
. . Q . . .
. . . . . Q
. Q . . . .
. . . . Q .
Q . . . . .
. . . Q . .
. . . Q . .
Q . . . . .
. . . . Q .
. Q . . . .
. . . . . Q
. . Q . . .
. . . . Q .
. . Q . . .
Q . . . . .
. . . . . Q
. . . Q . .
. Q . . . .
```







answer:If there is no answer, please comment