1049: Shortest path to the target
[Creator : ]
Description
Given a rectangular grid whose size is M*N (M rows and N columns), filled with either O, X, S, T, where O represents an open cell, X represents a blocked cell, and T represents the target grid and S represents the starting grid; please output the minimum steps from S grid to T grid. In this problem, only one grid is S and one grid is T. you are only allowed to travel either of the four directions, and diagonal moves are not allowed. If T grid cannot be reached, output -1.
Input
First line is two integers M and N
then followed by M*N grid of O, X, S, T , no spaces
then followed by M*N grid of O, X, S, T , no spaces
Output
one integer which is the minimum steps from S to T
Sample Input Copy
5 5
OOOOO
OSXXT
OOOXO
OXOOO
OOOOO
Sample Output Copy
5