#P8623. [蓝桥杯 2015 省 B] 移动距离
[蓝桥杯 2015 省 B] 移动距离
Description
In the residential area on Planet X, all buildings are identical and are arranged in a grid. The buildings are numbered .
When one row is filled, the numbering in the next row continues from the adjacent building but in the opposite direction.
For example, when the row width is , the numbering starts like this:
1 2 3 4 5 6
12 11 10 9 8 7
13 14 15 .....
The task is: given two building numbers and , find the shortest moving distance between them. (Diagonal movement is not allowed.)
Input Format
The input contains integers separated by spaces, all in the range from to .
Here, is the row width, and are the building numbers to compute.
Output Format
Output one integer, representing the shortest moving distance between buildings and .
6 8 2
4
4 7 20
5
Hint
Time limit: 1 second, 256M.
Lanqiao Cup 2015 Provincial Contest Group B, Problem H.
Translated by ChatGPT 5
京公网安备 11011102002149号