#P8628. [蓝桥杯 2015 国 AC] 穿越雷区
[蓝桥杯 2015 国 AC] 穿越雷区
Description
The tank in Planet is very strange. It must cross positive-energy radiation zones and negative-energy radiation zones alternately to keep running normally; otherwise, it will be scrapped.
A tank needs to go from zone to zone (zones and themselves are safe zones, with neither positive-energy nor negative-energy properties). How should it move to make the path as short as possible?
The known map is a square grid. The grid marks zones and with letters. All other zones are marked with a plus sign or a minus sign, representing positive-energy and negative-energy radiation zones, respectively.
For example:
A + - + -
- + - - +
- + + + -
+ - + - +
B + - + -
The tank can only move to an adjacent zone horizontally or vertically.
Input Format
The first line contains an integer , representing the size of the square grid, .
The next lines each contain entries, each being one of A, B, +, -, separated by spaces.
Output Format
Output an integer representing the minimum number of moves for the tank to get from zone to zone .
If there is no solution, output .
5
A + - + -
- + - - +
- + + + -
+ - + - +
B + - + -
10
Hint
Time limit: 1 second, 512 MB. Lanqiao Cup, 2015, 6th National Finals.
Translated by ChatGPT 5
京公网安备 11011102002149号