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

Разделы > Linear Data Structures: Arrays > задача:


51127 - Maze solver

Задачи раздела

• 50982 - A thief in labyrinth
• 50989 - Rectangles and Points
• 50932 - Shifting rows and columns
• 50497 - Falling Bricks - Revisited
• 50933 - Sum of the Biggest Neighbors
• 50444 - n digit kth number divisible...
• 50865 - Apartment Building Adminis...
• 50874 - Apartment Building Adminis...
• 51127 - Maze solver
• 51126 - Dr. Fllanxha
• 51021 - Number of Nodes
• 51044 - Number of Trees
• 51098 - Rotate a matrix
• 51061 - The Longest Path
• 51083 - Grades Histogram
• 51084 - Reflect a matrix
• 51011 - Decoding the Path

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

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

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

Maze solver

You are given a maze where the walls are encoded with the numbers:
  • 1: There is a wall at the top and it is blocked
  • 2: Right of the cell is blocked
  • 4: Bottom of the cell is blocked
  • 8: Left of the cell is blocked
Thus, 12 means there are walls on the left and bottom of the cell and the doors on the other two walls are open.

Question: Write a program that reads a 2D array of integers, and defines the shortest path from upper left corner to the bottom right corner.

Input specification: First, you will be given two numbers (n and m) size of maze. Then, you will be given m numbers in the following n lines where the numbers are between 0 and 15 and 1 ≤ (n and m) ≤ 100.

Output specification: Show one integer: minimum number of steps to reach. Show minus 1 if there is no path.

Sample Input 1 Sample Input 2
6 5
11 9 1 5 7
8 6 10 13 3
10 11 8 3 10
14 8 6 12 2
13 4 3 11 10
13 5 6 12 6
3 4
11 9 5 7
12 4 5 3
13 5 5 6
Sample Output 1 Sample Output 2
12 6



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

www.contester.ru