#P2385. [USACO07FEB] Bronze Lilypad Pond B
[USACO07FEB] Bronze Lilypad Pond B
Description
To entertain and exercise the cows, Farmer John built a beautiful pond. This rectangular pond is divided into rows and columns (). Some cells are surprisingly sturdy lilypads, some are rocks, and the rest are beautiful, pure, deep-blue water.
Bessie is practicing ballet. She stands on a lilypad and wants to jump to another lilypad. She can only jump from a lilypad to another lilypad; she cannot jump onto water or rocks.
Bessie’s steps are like a knight’s moves in chess: each time she either moves horizontally squares () and then vertically squares (, ), or vertically squares and then horizontally squares. At most, Bessie has eight possible movement directions.
Given the pond layout and Bessie’s jump lengths, compute the minimum number of jumps needed for Bessie to go from the start to the destination. It is guaranteed that the destination in the input is reachable.
Input Format
The first line contains four space-separated integers: , , , and .
The second line through line : for each from to , line contains space-separated integers describing row of the pond: for water, for lilypad, for rock, for Bessie’s starting cell, and for Bessie’s destination.
Output Format
The first line contains the minimum number of moves from the start to the destination.
4 5 1 2
1 0 1 0 1
3 0 2 0 4
0 1 2 0 0
0 0 0 1 0
2
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号