ГлавнаяСборникиТурнирыРазделыФорумыУчастникиПечатьПомощьО системе

Сборники > Data Structures > задача:


50997 - Dynamic Knights

Задачи сборника

• 51067 - Jumping frog
• 50840 - Tanker trucks
• 51080 - Deepest Point
• 51079 - Key person - 2
• 50877 - Friendly Queue
• 51021 - Number of Nodes
• 51044 - Number of Trees
• 50876 - He is my cousin
• 50997 - Dynamic Knights
• 50816 - Largest Sum Path
• 50857 - Nine-Stones Game
• 50490 - Across the River
• 50837 - Sum is equal to K
• 51010 - Max Sequential Sum
• 50772 - The Path of a Node
• 50936 - Saving the Soldiers
• 51086 - Top popular student

Обратная связь

Если у вас есть предложения или пожелания по работе Contester, посетите форум сайта www.contester.ru.

Лимит времени 2000/4000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб.
Question by Ibrahim Mesecan.

Dynamic Knights

Your knights had limitations therefore they could fight in a smaller area. Now, they have taken algorithms course and they are dynamic knights who can fight in a wider area: 400 x 400 board. See the image for orientation and possible moves. If you are given the initial (xi, yi) and the final (xf, yf) coordinates, and if you are also given m positions which are occupied by other pieces where the knight cannot move on them.

Question:
Write a program that tries all possible moves and decides the fastest move where the knight can move over the destination (xf, yf) cell.

Input specification
Firstly, you will be first given 2 integers

  • The size of the board (n) where the board is an nxn matrice and 1 ≤ n ≤ 400
  • The number of cells (m) occupied by other pieces where 0 ≤ m ≤ 5000
Then in the following line you will be given four integers initial (xi, yi position of the knight and the position that the knight wants to reach (xf, yf). Then, in the following m lines you will be given (x,y) coordinates of m occupied cells.

Output specification
Show the minimum number of moves that the knight can reach to the destination. Show -1, if the knight cannot reach to the destionation.

Sample Input I
3 1
1 1 2 2
1 2
Sample Input II
4 2
1 1 2 4
4 1
4 2
Sample Output I  
-1
Sample Output II
2


Для отправки решений необходимо выполнить вход.

www.contester.ru