Frog VS mosquito: the last fight!
The forest swamp is divided into 8 * 8 identical cells. A frog sits in one of the cells, and a mosquito flies over some other cell. The frog wants to eat a mosquito, and the mosquito tries to fly away from it (avoiding death in the belly of a frog). The frog and the mosquito move in turn.
In one jump, the frog moves horizontally or vertically to any non-zero number of cells. The mosquito in one flight moves to one of the 8 neighboring cells (horizontally, vertically or diagonally). If a frog jumps through a cell, over which there is a mosquito or jumps directly to this cell, then it eats the mosquito. The frog can move one square diagonally, if this way it eats the mosquito.
Make a program that, given the initial position of the frog and the mosquito, will determine if the frog can eat a mosquito.
A frog and a mosquito can not miss the moves (can not stay in place). The mosquito and the frog can be on the same cell, and if this happened in the frog move, then no move will lead to the mosquito being eaten.
Input
Contains some (up to 1000) tests. Each test is given in separate line and contains 5 numbers X[L] Y[L] X[K] Y[K] M
, space separated. Here X[L] Y[L]
is the starting frog's position, X[K] Y[K]
is the starting mosquito's position, M means who makes first move: 0 - frog, 1 - mosquito.
The end of the tests is given by the number 0 in a separate line.
Output
Print for each test the answer in a separate line. You should print YES if, under the optimal strategy of both, the frog will eat a mosquito, and NO otherwise.