Pac-man P87462


Statement
 

pdf   zip

thehtml

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.

Public test cases
  • 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
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Salvador Roura
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++