#P1649. Obstacle Course S
Obstacle Course S
题目描述
Consider an N x N (1 <= N <= 100) square field composed of 1
by 1 tiles. Some of these tiles are impassible by cows and are marked with an 'x' in this 5 by 5 field that is challenging to navigate:
. . B x .
. x x A .
. . . x .
. x . . .
. . x . .
Bessie finds herself in one such field at location A and wants to move to location B in order to lick the salt block there. Slow, lumbering creatures like cows do not like to turn and, of course, may only move parallel to the edges of the square field. For a given field, determine the minimum number of ninety degree turns in any path from A to B. The path may begin and end with Bessie facing in any direction. Bessie knows she can get to the salt lick.
题目大意
方格中, 表示不能行走的格子, 表示可以行走的格子。卡门很胖,故而不好转弯。现在要从 点走到 点,请问最少要转 度弯多少次?
输入格式
第一行一个整数 ,下面 行,每行 个字符,只出现字符:,表示上面所说的矩阵格子,每个字符后有一个空格。
输出格式
一个整数:最少转弯次数。如果不能到达,输出 。
3
. x A
. . .
B x .
2
提示
只可以上下左右四个方向行走,并且不能走出这些格子之外。开始和结束时的方向可以任意。
数据范围及约定
对于全部数据,保证 。