HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Sections > Exhaustive search & Backtracking > problem:


50714 - The knight

Guest
• Discussion of problem (1)

Section problems

• 50707 - Rebus
• 50265 - Liars and Knights
• 51071 - Phalanx-2
• 50715 - Zero Sum
• 50711 - Snail Trails
• 50472 - Minimum Sum Triangle
• 50306 - Beautiful Numbers
• 50716 - All Palindromes
• 50714 - The knight
• 50713 - Castle and the girls
• 50710 - Permutations
• 50709 - k-ary Strings
• 50708 - Binary Strings
• 50996 - Checkers - the shortest path
• Check-Mate
• 50479 - Bit Compressor
• 50486 - Problems and Programmers

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
Prepared by: Ilir Capuni.

The Knight

Suppose that you are given a chess board with n x n fields. A knight is set at position (x,y).

Write a program that draws the path of n^2-1 moves, such that the knight visits each field exactly once.

The knight moves in a ‘L’ fashion, meaning that it can do two moves and then turn in both x and y direction.

Input description: You will be given an integer n (4<=n<=6) and two integers x and y (1<=x,y<=n) representing the coordinates of the position where the knight starts.

Note: The coordinates of the knight start from 1 to n with (1,1) being the upper left corner of the matrix.

Output description: Show one possible solution of the puzzle in a nxn matrix or “Impossible” if not possible.

 

Sample 1

Sample 2

Input:

5

1 1

6

1 1

Output:

1 6 15 10 21

14 9 20 5 16

19 2 7 22 11

8 13 24 17 4

25 18 3 12 23

1 12 21 28 7 10

22 29 8 11 20 27

13 2 23 4 9 6

30 35 32 17 26 19

33 14 3 24 5 16

36 31 34 15 18 25

Explaination for sample 1:
The knight starts at (1,1) so this is his first position. Then it moves to (2, 3) so we put 2 here as this is his second position. Then it moves to (5,3) so this is it’s 3rd position. And so on with the cell (1,5) being it’s 25th and last position.

Äëÿ îòïðàâêè ðåøåíèé íåîáõîäèìî âûïîëíèòü âõîä.

www.contester.ru