英文描述
Elevator (20)
The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to move down one floor. The elevator will stay for 5 seconds at each stop.
For a given request list, you are to compute the total time spent to fulfill the requests on the list. The elevator is on the 0th floor at the beginning and does not have to return to the ground floor when the requests are fulfilled.
Input Specification:
Each input file contains one test case. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100.
Output Specification:
For each test case, print the total time on a single line.
Sample Input:
3 2 3 1
Sample Output:
41
中文描述
反转素数
在我们的城市中一个高层建筑只有一个电梯。一个请求列表是有N个正数组成。在这列表中,这个数字意味着电梯会在相应的层数停止。电梯需要花费6秒上一层,花费4秒下一层。电梯在每一层停留5秒。
对于一个给出的请求列表,你需要计算出电梯在这个列表中实现上上下下所花费的总时间。这个电梯从第0层开始运作,并且完成列表请求的那些层数后不用再回到0层。
输入规格:
每一个输入包含一个测试用例。每个用例包含一个正整数N,接着是N个正数。所有的数字小于100。
输出规格:
对于每个测试用例,在一行内输出电梯总运行时间。
样例输入:
3 2 3 1
样例输出:
41
分析与解题
此题虽然简单,但也不好读懂题意。默认添加一个0进去,一个循环就搞定。判断第一个数和第二个数的大小,第一个数大于第二个数,电梯向下,否则电梯向上,之后进行相应的累加。
C语言实现
1 |
|