题目描述
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.
翻译:我们城市中最高的楼只有一部电梯。一个需求列表有N个正整数组成。这些数字表示电梯会在哪层停止,按照特定的顺序。电梯每上一层会花费6s,每下一层会花费4s,每次停留5s。
INPUT FORMAT
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.
翻译:每个输入文件包含一组测试数据,每组测试数据包括一个正整数N,和N个正整数组成。所有的输入数字都小于100。
OUTPUT FORMAT
For each test case, print the total time on a single line.
翻译:对于每组测试数据,单独一行输出所运行的总时间。
Sample Input:
3 2 3 1
Sample Output:
41
解题思路
这道题直接模拟题目所说的要求即可。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#define INF 99999999
using namespace std;
int N;
int main(){
scanf("%d",&N);
int a,pre=0,sum=0;
for(int i=0;i<N;i++){
scanf("%d",&a);
if(a>=pre)sum+=(a-pre)*6,pre=a;
else sum+=(pre-a)*4,pre=a;
sum+=5;
}
printf("%d\n",sum);
return 0;
}