#C1527. Minimum Knight Moves
Minimum Knight Moves
Minimum Knight Moves
In a standard chess game, the knight moves in an "L" shape: two squares in one direction and one in the perpendicular direction. Given an 8×8 chessboard and two positions on the board, your task is to compute the minimum number of moves required for a knight to travel from the starting position to the target position. The board positions are represented by two integers for each coordinate (x and y), where both x and y lie between 1 and 8 inclusive.
The knight's move is defined by any of the eight possible moves:
[ (2, 1),\ (1, 2),\ (-1, 2),\ (-2, 1),\ (-2, -1),\ (-1, -2),\ (1, -2),\ (2, -1) ]
It is guaranteed that the destination can always be reached with a valid sequence of moves.
inputFormat
The input is read from standard input (stdin) as a single line containing four integers separated by spaces:
- start_x: the starting x-coordinate (1 ≤ start_x ≤ 8),
- start_y: the starting y-coordinate (1 ≤ start_y ≤ 8),
- end_x: the target x-coordinate (1 ≤ end_x ≤ 8),
- end_y: the target y-coordinate (1 ≤ end_y ≤ 8).
outputFormat
The output is a single integer printed to standard output (stdout), representing the minimum number of moves required for the knight to reach the destination.
## sample1 1 8 8
6