HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Winner's Camp > problem:


06. 50714 - The knight

Guest
• Discussion of problem (1)

Volume problems

• 51004 - Word Search Game
• 01. 50722 - Scientist's problem
• 02. 50376 - Sequences
• 03. 50673 - DNA Testing
• 04. 50649 - Puzzle
• 05. 50713 - Castle and the girls
• 06. 50714 - The knight
• 07. 50715 - Zero Sum
• 08. 50370 - Number of rectangles in ...
• 09. 50716 - All Palindromes
• 10. 50475 - Voice advertising
• 11. 50476 - Meditation
• 12. 50723 - Tribonacci

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