#B3814. General's Rook Trap via a Knight Move
General's Rook Trap via a Knight Move
General's Rook Trap via a Knight Move
In Chinese chess, the knight (horse) moves in an L‐shaped pattern. Using \((i,j)\) to denote the grid at row \(i\) and column \(j\), the knight at \((i,j)\) (ignoring leg blocking) can jump to the following eight positions, as long as the destination is within the board:
\[ \begin{array}{cccc} (i-2,j+1), & (i-2,j-1), & (i-1,j+2), & (i-1,j-2),\\ (i+1,j+2), & (i+1,j-2), & (i+2,j+1), & (i+2,j-1)\\ \end{array} \]
The tactic known as "General's Rook Trap" involves a knight move that simultaneously gives check to the enemy general and positions the knight to attack the enemy rook. Consider a simplified scenario where there is exactly one red general, one red rook, and one black knight on the board. We do not consider whether the general is protected or any leg blocking issues; the only concern is whether, on the current turn for Black, the knight can move (without going off board) such that from its landing square it would be able to check the general and also have the red rook in its attack range.
Note that the board is taken as a standard Chinese chess board with 10 rows and 9 columns. All coordinates are given as \( (row, column) \) with rows in \([1,10]\) and columns in \([1,9]\).
Task: Given the positions of the black knight, the red general, and the red rook, determine whether the black knight can make a single move to a legal square such that from that square it can move (in the knight's characteristic L-shape) to both the red general's position and the red rook's position.
inputFormat
The input consists of a single line containing six integers:
\(kx\, ky\, gx\, gy\, rx\, ry\)
where \((kx, ky)\) is the position of the black knight, \((gx, gy)\) is the position of the red general, and \((rx, ry)\) is the position of the red rook.
outputFormat
Output a single line with YES
if there exists a legal knight move meeting the criteria described (i.e. from the landing square, both the red general and red rook lie in the knight's attack range), otherwise output NO
.
sample
5 5 1 5 2 8
YES