22847_Shopping

2022-5-16 18:23| 发布者: Hocassian| 查看: 28| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-5-8950714950500-Problem List-采集的数据-后羿采集器.html

Pro.ID

22847

Title

Shopping

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=22847

AC

23

Submit

36

Ratio

63.89%

时间&空间限制

  • Time Limit: 1000/500 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    Saya and Kudo go shopping together.

    You can assume the street as a straight line, while the shops aresome points on the line.

    They park their car at the leftmost shop, visit all the shops from left to right, and go back to their car.

    Your task is to calculate the length of their route.

    输入

    The input consists of several test cases.

    The first line of input in each test case contains one integer N ( 0 < N < 100001 ), represents the number of shops.

    The next line contains N integers, describing the situation of the shops. You can assume that the situations of the shops are non-negative integer and smaller than 230.

    The last case is followed by a line containing one zero.

    输出

    Description

    Saya and Kudo go shopping together.

    You can assume the street as a straight line, while the shops aresome points on the line.

    They park their car at the leftmost shop, visit all the shops from left to right, and go back to their car.

    Your task is to calculate the length of their route.

    Input

    The input consists of several test cases.

    The first line of input in each test case contains one integer N ( 0 < N < 100001 ), represents the number of shops.

    The next line contains N integers, describing the situation of the shops. You can assume that the situations of the shops are non-negative integer and smaller than 230.

    The last case is followed by a line containing one zero.

    Output

    For each test case, print the length of their shopping route.

    Sample Input

    4
    24 13 89 37
    6
    7 30 41 14 39 42
    0

    Sample Output

    152
    70

    Hint

    Explanation for the first sample: They park their car at shop 13; go to shop 24, 37 and 89 and finally return to shop 13. The total length is (24-13) +(37-24) + (89-37) + (89-13) = 152

    Source

    样例输入

    4
    24 13 89 37
    6
    7 30 41 14 39 42
    0

    样例输出

    152
    70

    提示

    Explanation for the first sample: They park their car at shop 13; go to shop 24, 37 and 89 and finally return to shop 13. The total length is (24-13) +(37-24) + (89-37) + (89-13) = 152


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部