PTA 1008 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
结尾无空行

解题思路

inputList = list(map(int,input().split()))
# inputList = list(map(int,"3 2 3 1".split()))
res = 0
res += inputList[0]*5
eleList = [0]+inputList[1:]
for i in range(1,len(eleList)):
    #升
    if eleList[i]>=eleList[i-1]:
        res += 6*(eleList[i]-eleList[i-1])
    else:
        res += 4 * (eleList[i-1] - eleList[i])
print(res)


目录
相关文章
|
6月前
|
测试技术 索引
敲笨钟ptaC++
敲笨钟ptaC++
30 0
【PTA】7-8 到底有多二 (15分)
【PTA】7-8 到底有多二 (15分)
2219 0
|
5月前
|
存储 C++ 索引
【PTA】L1-059 敲笨钟(C++)
【PTA】L1-059 敲笨钟(C++)
28 1
|
6月前
|
C++
【PTA】L1-054 福到了(C++)
【PTA】L1-054 福到了(C++)
49 0
【PTA】L1-054 福到了(C++)
|
6月前
|
人工智能
PTA-排序问题
排序问题
37 0
|
6月前
12.08 PTA练习
12.08 PTA练习
PTA 7-4 胖达与盆盆奶 (20 分)
俗称“胖达”,会排队吃盆盆奶。它们能和谐吃奶的前提,是它们认为盆盆奶的分配是“公平”的,即:更胖的胖达能吃到更多的奶,等胖的胖达得吃到一样多的奶。
179 0
L1-057 PTA使我精神焕发 (5 分)
L1-057 PTA使我精神焕发 (5 分)
94 0
L1-057 PTA使我精神焕发 (5 分)
PTA 7-1 多二了一点 (15 分)
若一个正整数有 2n 个数位,后 n 个数位组成的数恰好比前 n 个数位组成的数多 2,则称这个数字“多二了一点”。
120 0
PTA 1088 三人行 (20 分)
子曰:“三人行,必有我师焉。择其善者而从之,其不善者而改之。”
86 0