cai
On a square game table sized
NxN there are p
white knights and a black knight.
The initial positions of the knight
are known. The knights
are moved like in the chess game, as shown in the next figure (the knight
in the position denoted by
C may be moved in any of the eight positions denoted by X,
on the under the condition that the knight
stays on the game table).
Task
Determine the minum total number of moves for the white knights, in order to keep the black knight blocked in his initial position. The black knight does not make any moves.
Input data
Input file cai.in contains on the first line the integers N and p, separated by a blank. The second line contains two integers L and C, representing the position of the black knight (line L, column C). The next p lines contain each two integers separated by a blank Li and Ci, representing the positions of the white knights.
Output data
Output file cai.out will contain a single line with a positive integer representing the minum total number of moves for the white knights, in order to keep the black knight blocked in his initial position.
Constraints
3 <= N <= 50Example
cai.in |
cai.out |
Explanation |
4 4 |
2 |
The knight in position (1,2) is moved twice :(1,2)->(2,4) ->(4,3), the other knights stay on their initial positions. |
Time limit: 0.15 seconds
prof. Alin Burta
Colegiul National "B.P. Hasdeu" Buzau
Contact: allbu2003@yahoo.com