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

PROGRAMMING:n-queens problem

Luz5年前 (2021-05-10)题库430
On the n * n chessboard, place n queens. Each queen is required to have different rows, columns and left and right diagonals.
Where n does not exceed 10.
Requirement: output all solutions.
Algorithm tip: use stack to solve queen problem.
![ QQ picture 20190404091217. PNG] (~ / acf816c5-54b6-47a0-acc5-58ff30e1f309. PNG)
###Input format:
Enter n
###Output format:
Output each solution line by line, expressed by the position coordinates of each queen, there is a space character after each position coordinate, and output the last empty line.
###Input example:
Here is a set of inputs. For example:
```in
six
```
###Output example:
The corresponding output is given here. For example:
```out
1: (1,2) (2,4) (3,6) (4,1) (5,3) (6,5)
2: (1,3) (2,6) (3,2) (4,5) (5,1) (6,4)
3: (1,4) (2,1) (3,5) (4,2) (5,6) (6,3)
4: (1,5) (2,3) (3,1) (4,6) (5,4) (6,2)
```







answer:If there is no answer, please comment