Let us define an knight as a piece that moves by jumping cells in one direction and cells in the other direction, where the possible directions are horizontal and vertical. For instance, the traditional chess knight is a knight.
Given an board with obstacles, an initial position , a final position , and the pair , can you tell if an knight initially located at can reach in two or less steps? The knight can never leave the board, nor visit any obstacles.
Input consists of several cases, each with
and
,
followed by the board
(
lines with
characters
each, where an ‘X’ indicates an obstacle and a
‘.’ indicates a free cell), followed by
,
,
,
,
and
.
Assume that
and
are between 1 and 42, that
and
are free positions inside the board, and
.
The upper-left position is
.
For every case, print “yes” or “no”
depending on whether the goal position is reachable from the initial
position in two or less steps.
Input
2 3 ... ... 0 0 1 2 1 2 4 5 ..... XXXXX XXXXX ..... 0 1 3 0 1 3 5 5 .XXX. XXXXX XXXXX XXXXX XX.XX 0 4 0 0 2 4 5 5 .XXX. XXXXX XXXXX XXXXX XXXXX 0 4 0 0 2 4 1 8 XXXXXXX. 0 7 0 7 3 5
Output
yes yes yes no yes