A higher resolution is required to access the IDE
- 17
Learning Opportunities
This puzzle can be solved using the following concepts. Practice using these concepts and improve your skills.
Statement
Goal
A legendary item has been rediscovered by Brodo and must be destroyed to prevent the Dark Lord's return to power. The only way to destroy the item is for Brodo to travel to Mount Boom and to cast it into the flames. The goal is to find the SHORTEST DISTANCE for Brodo to reach Mount Boom.Movement:
Brodo can move in any CARDINAL or ORDINAL direction (
Brodo CANNOT travel onto mountains, nor can he move diagonally between two mountains that are adjacent to each other.
Mountains are considered adjacent if they are within
Example:
Brodo cannot move directly from B to M, or vice versa, in the following map:
B^
^M
Map Legend:
Space - Empty path Brodo can traverse, following the movement rules above.
Input
Line 1: Space separated integers representing the height and width of the map, in the form: h w.
Next h lines: String of length w representing a section of the map.
Next h lines: String of length w representing a section of the map.
Output
Integer of the shortest distance from Brodo's starting position to Mount Boom, in the unit league (s ).
Constraints
2 ≤ h, w < 50
Map contains only a singleB and M .
Map contains only a single
Example
Input
6 5 ^^^^^ ^^M ^ ^ ^ ^^ ^^ ^ B^^ ^^^^^
Output
3 leagues
A higher resolution is required to access the IDE