题目描述

In Exercise 7.22, we developed a solution to the Knight’s Tour problem. The approach used, called the “accessibility heuristic,” generates many solutions and executes efficiently.
As computers continue increasing in power, we’ll be able to solve more problems with sheer computer power and relatively unsophisticated algorithms. This is the “brute force” approach to problem solving.
Use random number generation to enable the knight to walk around the chessboard (in its legitimate L-shaped moves, of course) at random. Your program should run one tour and print the final chessboard.
Assume the knight start from [0, 0] (row, column).
Remember to test each potential move, starting from the random moveNumber.

horizontal[ 0 ] = 2 vertical[ 0 ] = -1
horizontal[ 1 ] = 1 vertical[ 1 ] = -2
horizontal[ 2 ] = -1 vertical[ 2 ] = -2
horizontal[ 3 ] = -2 vertical[ 3 ] = -1
horizontal[ 4 ] = -2 vertical[ 4 ] = 1
horizontal[ 5 ] = -1 vertical[ 5 ] = 2
horizontal[ 6 ] = 1 vertical[ 6 ] = 2
horizontal[ 7 ] = 2 vertical[ 7 ] = 1

输入格式

Input a random seed to generate random number. The random number determine which moveNumber of 8 L-shaped move you take first.


输出格式

Print the final chessboard


样例数据

输入

1

输出

  1  8  5  0 33  0 39 26
  6  0  2  0  4 27 34  0
  9  0  7  0 29 32 25 38
  0 15 30  3  0 35 28  0
  0 10 19 14 31  0 37 24
 16  0  0 21 36  0  0  0
 11 20  0 18 13  0 23  0
  0 17 12  0 22  0  0  0

备注

You can use function rand() to generate random number


操作

评测记录

优秀代码

信息

时间限制: 1s
内存限制: 128MB
评测模式: Normal

题解