<title>2015 Blue Bridge Cup: 8. Moving distance</title> 2015 Blue Bridge Cup: 8. Moving distance
13 min I used a two-dimensional array simulation, as if no simulation is OK, do not know how many points ...
The buildings of planet X are all the same and arranged in a matrix style. The number of its buildings is ...
When a row is full, from the next line of the adjacent building to the opposite direction to automatic arranging.
For example: When the cell automatic arranging width is 6 o'clock, the situation begins as follows:
1 2 3 4 5 6
12 11 10 9 8 7
13 14 15 .....
Our problem is: Known two building numbers m and N, need to require the shortest moving distance between them (can not move diagonally direction)
Input is 3 integers w m n, spaces separated, all within 1 to 10000 range
W is automatic arranging width, m,n is the building number to be calculated.
An integer is required to indicate the shortest moving distance between two floors of M N.
For example:
User input:
6 8 2
Then, the program should output:
4
Again for example:
User input:
4 7 20
Then, the program should output:
5
2015 Blue Bridge Cup: 8. Moving distance