#P4554. 小明的游戏
小明的游戏
Description
Xiao Ming recently enjoys playing a game. Given an board with two types of cells # and @. The rules are simple: given a starting position and a target position, each step Xiao Ming can move one cell in one of the four directions: up, down, left, or right. If he moves onto a cell of the same type, the cost is ; otherwise, the cost is . Write a program to compute the minimum cost to move from the starting position to the target position.
Input Format
The input contains multiple test cases.
The first line of each test case contains two integers , , the number of rows and columns of the board.
The next lines each contain cells (denoted by # or @).
The next line contains four integers , the starting position and the target position, respectively.
The input ends when both and are .
Output Format
For each test case, output the minimum cost from the starting position to the target position. Print one result per line.
2 2
@#
#@
0 0 1 1
2 2
@@
@#
0 1 1 0
0 0
2
0
Hint
- For 20% of the testdata: .
- For 40% of the testdata: .
- For 100% of the testdata: .
Translated by ChatGPT 5
京公网安备 11011102002149号