Pro.ID22046 TitleMax's game Title链接http://10.20.2.8/oj/exercise/problem?problem_id=22046 AC0 Submit5 Ratio0.00% 时间&空间限制描述Max is lately playing a game. Given a n*m board, there are only two types of grid on it: # and @. And the rule is simple: Given a start position to Max, and Max can move to four direction for each step, up, down, left, right. When moving between two same type grids, it costs zero, otherwise, it costs one. Now, Max gets two different positions on the board: the start position and the target position, he wants to know how many costs he need to spend to achieve the game at least. 输入Input contains multiple test data sets. For each data set, first comes two integers in one line: n, m ( 1 ≤ n, m ≤ 500 ), stands for the number of row and the number of column of the board. Then comes n lines with m grid characters per each. The characters are only @ or #. Then four integers in one line follow: x1, y1, x2, y2 ( 0 ≤ x1, x2 < n, 0 ≤ y1, y2 < m ) which is the start position and the end position correspondingly. Input is terminated by EOF. 输出Description Max is lately playing a game. Given a n*m board, there are only two types of grid on it: # and @. And the rule is simple: Given a start position to Max, and Max can move to four direction for each step, up, down, left, right. When moving between two same type grids, it costs zero, otherwise, it costs one. Now, Max gets two different positions on the board: the start position and the target position, he wants to know how many costs he need to spend to achieve the game at least. Input Input contains multiple test data sets. For each data set, first comes two integers in one line: n, m ( 1 ≤ n, m ≤ 500 ), stands for the number of row and the number of column of the board. Then comes n lines with m grid characters per each. The characters are only @ or #. Then four integers in one line follow: x1, y1, x2, y2 ( 0 ≤ x1, x2 < n, 0 ≤ y1, y2 < m ) which is the start position and the end position correspondingly. Input is terminated by EOF. Output For each test data set, one output data set should be generated as follow: Generates one line containing one integer which indicates the minimum cost Max need to take for the game. Sample Input 2 2 Sample Output 2 Source 样例输入2 2 样例输出2 作者 |