PAT 甲级 1008 Elevator(25)

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

Experiential Summing-up

这道题过于简单,实在没什么可说的。

需要注意的是,当电梯到达最后一层时也是需要停留5s的。

Accepted Code 

复制代码
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int n, sum;
 4 int a[1000];
 5 
 6 int main()
 7 {
 8     a[0] = 0;
 9     cin >> n;
10     for(int i = 1; i <= n; i ++)
11     {
12         int c;
13         cin >> a[i];
14         c = a[i] - a[i-1];
15         if(c > 0) sum += c*6+5;
16         else sum += -c*4+5;
17     }
18     cout << sum;
19     return 0;
20 }
复制代码

 

posted @   爱吃虾滑  阅读(9)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示