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 consists of several cases. Every case begins with the number of
rows
and the number of columns
of the board. Follow
rows with
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
and
,
that the rows and columns on the edge of the board only have walls, and
that each board has exactly one ‘P’.
For every case, tell if Pac-man can eat any pellet or not.
Input
6 10 XXXXXXXXXX X........X X....XXX.X XP.F...X.X X....F.XBX XXXXXXXXXX 7 12 XXXXXXXXXXXX X.......BF.X X.........XX X.F..P...X.X X.......X..X X.B..F.X.B.X XXXXXXXXXXXX 3 5 XXXXX XFPBX XXXXX 6 8 XXXXXXXX X.....BX X.P.F..X X...F..X X.....BX XXXXXXXX
Output
yes no no no