PAT甲级 1008. Elevator (20分)

简介: PAT甲级 1008. Elevator (20分)

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
结尾无空行
#include <iostream>
using namespace std;
int main()
{
    int N;
    cin >> N;
    int A[N];
    int sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        if (i == 0)
        {
            sum += A[i] * 6;
            continue;
        }
        int tmp = A[i] - A[i - 1];
        if (tmp > 0)
        {
            sum += tmp * 6;
        }
        else
        {
            sum += tmp * (-4);
        }
    }
    sum += 5 * N;
    cout << sum;
    return 0;
}
目录
相关文章
【PTA】7-8 到底有多二 (15分)
【PTA】7-8 到底有多二 (15分)
2164 0
|
10月前
|
C++
【PAT甲级 - C++题解】1008 Elevator
【PAT甲级 - C++题解】1008 Elevator
46 0
|
10月前
|
调度 C语言 C++
PTA L2-014 列车调度(25分)
两端分别是一条入口(Entrance)轨道和一条出口(Exit)轨道,它们之间有N条平行的轨道。每趟列车从入口可以选择任意一条轨道进入,最后从出口离开。在图中有9趟列车,在入口处按照{8,4,2,5,3,9,1,6,7}的顺序排队等待进入。如果要求它们必须按序号递减的顺序从出口离开,则至少需要多少条平行铁轨用于调度? 输入格式: 输入第一行给出一个整数N (2 ≤ N ≤105),下一行给出从1到N的整数序号的一个重排列。数字间以空格分隔。 输出格式: 在一行中输出可以将输入的列车按序号递减的顺序调离所需要的最少的铁轨条数。
90 0
|
10月前
|
存储
【PAT甲级】1122 Hamiltonian Cycle
【PAT甲级】1122 Hamiltonian Cycle
36 0
|
测试技术
PTA 1020 月饼 (25 分)
月饼是中国人在中秋佳节时吃的一种传统食品,不同地区有许多不同风味的月饼。
101 0
|
机器学习/深度学习 人工智能
PTA 7-3 拼题 A 是真爱 (20 分)
如果一个人在一段话里很多次提到 pintia,那对拼题 A 就是真爱啦~ 本题就请你检查一下给定的文字中出现了几次 pintia。
97 0
PTA 1053 住房空置率 (20 分)
在不打扰居民的前提下,统计住房空置率的一种方法是根据每户用电量的连续变化规律进行判断。
93 0
PTA 7-4 胖达与盆盆奶 (20 分)
俗称“胖达”,会排队吃盆盆奶。它们能和谐吃奶的前提,是它们认为盆盆奶的分配是“公平”的,即:更胖的胖达能吃到更多的奶,等胖的胖达得吃到一样多的奶。
108 0
PTA 7-1 多二了一点 (15 分)
若一个正整数有 2n 个数位,后 n 个数位组成的数恰好比前 n 个数位组成的数多 2,则称这个数字“多二了一点”。
82 0