1008 Elevator (20)(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

PS:起初还想复杂了,看错以为当电梯不用的时候需要回到1层, 英语差没办法...

#include<iostream>
using namespace std;
int main() {
int n, now = 0, next, time = 0;
cin >> n;
for (int i = 0; i < n ; i++) {
cin >> next;
if (next - now > 0)
time += (next - now) * 6+5;
else
time += (now - next) * 4+5;
now = next;
}
cout << time;
return 0;
}

PAT 甲级 1008 Elevator (20)(代码)的更多相关文章

  1. PAT 甲级 1008 Elevator (20)(20 分)模拟水题

    题目翻译: 1008.电梯 在我们的城市里,最高的建筑物里只有一部电梯.有一份由N个正数组成的请求列表.这些数表示电梯将会以规定的顺序在哪些楼层停下.电梯升高一层需要6秒,下降一层需要4秒.每次停下电 ...

  2. PAT甲 1008. Elevator (20) 2016-09-09 23:00 22人阅读 评论(0) 收藏

    1008. Elevator (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The highest ...

  3. PAT 甲级 1008 Elevator

    https://pintia.cn/problem-sets/994805342720868352/problems/994805511923286016 The highest building i ...

  4. PAT Advanced 1008 Elevator (20 分)

    The highest building in our city has only one elevator. A request list is made up with N positive nu ...

  5. PAT Advanced 1008 Elevator (20) [数学问题-简单数学]

    题目 The highest building in our city has only one elevator. A request list is made up with N positive ...

  6. PAT甲级——1008 Elevator

    PATA1008 Elevator The highest building in our city has only one elevator. A request list is made up ...

  7. PAT 1008. Elevator (20)

    1008. Elevator (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The highest ...

  8. PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642 题目描述: The highest building in our city has ...

  9. 1008 Elevator (20分)

    1008 Elevator (20分) 题目: The highest building in our city has only one elevator. A request list is ma ...

随机推荐

  1. Hide-Music-Player 一个完整的音乐播放器《IT蓝豹》

    Hide-Music-Player 一个完整的音乐播放器 Hide-Music-Player 一个完整的音乐播放器,本例子主要包括几个点 (1)摇一摇进入播放器 (2)下拉展开新视图(扫描音乐) (3 ...

  2. FTP原理和虚拟用户映射登录-2019.2.8

    FTP主动模式和被动模式 FTP(File Transfer Protocol)是文件传输协议的简称.正如其名所示:FTP的主要作用,就是让用户连接上一个远程计算机(这些计算机上运行着FTP服务器程序 ...

  3. k近邻算法(KNN)

    k近邻算法(KNN) 定义:如果一个样本在特征空间中的k个最相似(即特征空间中最邻近)的样本中的大多数属于某一个类别,则该样本也属于这个类别. from sklearn.model_selection ...

  4. 梯度迭代树(GBDT)算法原理及Spark MLlib调用实例(Scala/Java/python)

    梯度迭代树(GBDT)算法原理及Spark MLlib调用实例(Scala/Java/python) http://blog.csdn.net/liulingyuan6/article/details ...

  5. 第三章,DNA序列的进化演变

    31.前言 3.1.两个序列间的核苷酸差异 来自同一祖先序列的两条后裔序列,之间的核苷酸的差异随着时间的增加而变大.简单的计量方法,p距离 3.2.核苷酸代替数的估计 3.3.Jukes和Cantor ...

  6. MyBatis数据库连接的基本使用-补充

    补充1  MyBatis使用过程中,返回值类型可能是Map,不一定是实体类 返回查询结果也可以是一个Map,不一定是实体类 (1)mybatis会先将查询结果返回为一个map,字段名作为key,字段值 ...

  7. Controlled Components

    [Controlled Components] In HTML, form elements such as <input>, <textarea>, and <sele ...

  8. python进程之守护进程

    标签(空格分隔): 守护进程 主进程创建子进程,然后将该进程设置成守护自己的进程,守护进程就好比崇祯皇帝身边的老太监,崇祯皇帝已死老太监就跟着殉葬了: 关于守护进程需要强调两点: 其一:守护进程会在主 ...

  9. 项目没有build path问题(转)

    感谢作者分享:https://blog.csdn.net/u012572815/article/details/76353018 问题1.通过eclipse的svn资源库添加的项目,显示的方式和直接创 ...

  10. linux 后台运行命令

    command & 关闭终端,程序会终止 nohup command & 关闭终端,程序不会终止