[openjudge] 746:Elevator Stopping Plan

来源:互联网 发布:你不知道的js pdf 编辑:程序博客网 时间:2024/06/05 09:48
描述
         Zsoft是一家在GaoKe大楼的软件公司,在这栋楼里所有工作人员都很勤奋。但是这栋楼里的电梯有毒。因为只有一个电梯,但是这栋楼里有上百个公司。每天早上,人们浪费了大量时间等电梯。Hal是ZSoft里的聪明人。想要改变这种状况。他想找一种可以有效利用电梯的方法,但这不容易。
        在大楼里有H层,电梯4s上一层,也就是如果从一楼到n楼要花(n-1)*4s的时间。电梯一次停10s,所以如果电梯停在每层要花 (n-1)*4+(n-2)*10s。如果不乘电梯,人们要花20s上/下一层,从一楼到n楼要花(n-1)*20s的时间。显然,这不是一个好主意,所以有些人想想使用电梯到达理他们办公室最近的一层。
         再想了很久,Hal最终找到改变这种状况的办法。他告诉电梯老头:首先,老头问人们要去哪一层,以便设计出停靠方案可以使最后一人到达办公室的时间最小。举个栗子,如果电梯需要停在4、5、10层,停靠方案就是4、10层。电梯会在12s到达第4层,在这层停10s后在46s到达第10层。想到5层的同学会在12+20s到达,又因为人们在46s到10层,因此最后一个人到办公室用了46秒,此乃最优解。
   
输入
The input consists of several test cases. Each test case is in a single line as the following:
n f1 f2 ... fn

It means, there are totally n floors at which the elevator need to stop, and n = 0 means no testcases
any more. f1 f2 ... fn are the floors at which the elevator is to be stopped (1<=n<=30000, 2<=f1< f2 ... fn<=30000). Every number is separated by a single space.
输出
For each testcase, output the time the last reading person needs in the a single line
样例输入
3 4 5 101 20
样例输出
464


0 0
原创粉丝点击