2015 Blue Bridge Cup: 8. Moving distance

Source: Internet
Author: User

<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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.