Pac-man

Given a rectangular board with Pac-Man in it, tell if Pac-man can eat
any power pellet. To get there, Pac-Man can only move horizontally and
vertically, never crossing a wall. Moreover, Pac-Man can never be too
close to a ghost. There should always be a cell between them, either
horizontally, vertically, or diagonally. Look at the input and output
examples.

Input

Input consists of several cases. Every case begins with the number of
rows r and the number of columns c of the board. Follow r rows with c
characters each. A ‘P’ indicates the initial position of Pac-Man. An ‘F’
indicates the position of a ghost (which does not move). A ‘B’ indicates
the position of a pellet. An ‘X’ indicates a wall. A dot indicates an
empty position. Assume 3 ≤ r ≤ 100 and 3 ≤ c ≤ 100, that the rows and
columns on the edge of the board only have walls, and that each board
has exactly one ‘P’.

Output

For every case, tell if Pac-man can eat any pellet or not.

Problem information

Author: Unknown
Translator: Salvador Roura

Generation: 2026-01-25T12:11:44.411Z

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