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

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


Check-Mate

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

• 50472 - Minimum Sum Triangle
• 50842 - Minimum Sum Triangle - DP
• 50781 - ReversesreveR
• 50676 - Cinema Millennium
• 50780 - Hot Potato - Revisited
• 50678 - The Jumping Rabbit
• 50793 - Top M Customers
• 51073 - Campus Tours for High Sch...
• Check-Mate
• Post Office Delivery
• 50993 - Products in store
• 50564 - Kovat e qumeshtit te mamase
• 50593 - Transportimi
• 50598 - Shuma minimale
• 50704 - Te lidhura?
• 50705 - Klubet e studenteve
• 50779 - Rruga me e shkurter ne lab...

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

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

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

Check-Mate

In Checkers game, players can move each piece only diagonally (see the image).

Question:
You are given a board configuration with some unmovable pieces. Write a program that finds the distance of the shortest path from a given starting coordinate to a destination. Note: The pieces cannot jump over pieces.

Input specification
Firstly, you will be first given 2 integers

  • Board size (n) where 1 ≤ n ≤ 200 and board is an n-by-n matrix
  • The number of preoccupied cells (m) where 0 ≤ m ≤ 1000
The second line contains four integers starting and destination (x, y) positions for the piece you are moving. The next m-lines contain (x, y) coordinates of preoccupied cells.

Output specification
If the destination is not reachable, show -1. Otherwise, show minimum distance to reach to the destination.

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


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

www.contester.ru