For above: two of the red horse, located in coordinates A board (9, 3), and the coordinates of B (6, 6). Point A horse on the next step, must conform to the "day", the mark of A point to go to the following point (1, 1), (10, 5), (8, 5), (7, 4), (7, 2), (8, 1) position, where there are horses point in any different color piece, can be A horse attacks, such as the guns in the location (7, 4), will be attacked by the horse, when the horse step, can according to walk again ", "way to go the next step.
The question now is: give A horse in the 10 * 9 position on the board, the coordinates of point A and give you another different color piece location B, please by writing program, calculated from A to B, at least need take how many steps.
Enter
In the input file (Chess) in the first row number N, N rows behind said every line of figures have a, b, c, d four Numbers, respectively, the coordinates of a horse (a, b) and different color piece b (c, d) position.
O
The output file (estdout. Pc2) line output N Numbers, each row Numbers, the smallest number of walking horse each set of data.
Sample input (4) in
3
1 1 2 3
1 1 3 1
1 1 6 5
Sample output (estdout. Pc2)
1
2
3
CodePudding user response:
L x2 - x1 y2 - y1 l=l + l zWhen z % 3=0, z/3
When z % 3=1, z/3 + 3
When z % 3=2, z/3 + 2
next humble opinion, don't like do not spray, didn't consider horse leg get stopped