上海交通大学软件学院project1
- 格式:pdf
- 大小:261.38 KB
- 文档页数:2
PROJECT 1: N-Queen Puzzle
Submission:
Only team leader submits the code and document (BRIEF description of your
solution or any other specification of your project) via E-Learning before deadline. Please indicate
ALL your team members’ ID and Name BOTH in your code and doc. And in your doc, please
briefly describe EACH member’s work in the project.
NOTE
: Each team must NOT be more than 3 people.
DUE: 11.59 PM April 16, 2010 (Friday).
Deadline can be extended with 10% penalty per day.
Submission will not be accepted 48 hours after the due date.
The eight queens puzzle is the problem of putting eight chess queens on an 8×8
chessboard such that none of them is able to capture any other. The puzzle has
been generalized to arbitrary n×n boards. Given n, you are to find solutions
to the N-queen puzzle.
Note: there are formulas that directly give solutions to N-queen problem, you
are not supposed to use any such formulas.
Part I
-------------------------------------------------------------------------------
Find one solution to the N-queen puzzle.
Input
The input contains multiple test cases. Each test case consists of a single
integer n between 8 and 100 (inclusive). A zero indicates the end of input.
Output
For each test case, output your solution on one line. The solution is a
permutation of {1, 2, ..., n}. The number in the i'th place means the i'th-column
queen in placed in the row with that number.
Sample Input
8
0
Sample Output
5 3 1 6 8 2 4 7
Part II
-------------------------------------------------------------------------------
Find the number of solutions to the N-queen puzzle, including symmetrical ones.
Input: number "n" as a command line parameter
Output: number of solutions
For instance, if your program is called "nqueen2":
$ nqueen2 8
92