The hungry knight

A knight is on a chess board. The knight can only move following the
usual chess rules (that is, moving two units in one coordinate, and one
unit in the other coordinate, for a total of up to eight possible
movements), as long as the knight does not leave the board, nor it
visits any forbidden cell. What is the minimum number of steps to reach
a carrot?

Input

Input consists of several cases. Each case begins with the number of
rows f and the number of columns c of the board, both between 3 and 200.
Follow f rows with c characters each. A ‘p’ indicates a carrot, an ‘X’
indicates a forbidden cell, and a period indicates a free cell. Every
case ends with the initial position (row and column) of the knight. The
left-most cell of the first row is (1, 1). The initial cell is always
free.

Output

For every case, if the knight can reach some carrot, print the minimum
number of steps. Otherwise, print “no”.

Problem information

Author: Unknown
Translator: Salvador Roura

Generation: 2026-01-25T10:19:22.873Z

© Jutge.org, 2006–2026.
https://jutge.org
