#P16292. [蓝桥杯 2026 省 Java A 组] 两栖作战
[蓝桥杯 2026 省 Java A 组] 两栖作战
Problem Description
Xiao Lan designed an amphibious combat mech that can automatically switch forms based on the terrain, so it can fight on both land and water.
The combat area is an grid. Each cell is represented by a character indicating its terrain:
0means land.1means water.
Xiao Lan starts at the top-left corner , and the goal is to reach the bottom-right corner .
In each move, Xiao Lan can move to one adjacent cell in one of the four directions: up, down, left, or right, but cannot move outside the grid.
If the terrain of the destination cell is different from the current cell, the mech will automatically switch forms once. If the two cells have the same terrain, no form switch is needed.
Now, please compute: from to , what is the minimum number of form switches required.
Input Format
The first line contains a positive integer , which is the side length of the grid.
The next lines each contain a 01 string of length , describing the terrain of the corresponding row.
Output Format
Output one integer, the minimum number of form switches from to .
5
01100
10110
10001
01111
11010
4
Hint
Constraints
For of the testdata, .
For all testdata, .
Translated by ChatGPT 5