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

题意:

电梯上楼需要6秒,下楼需要4秒并且再每一层会停留5秒。题目给N个数字代表楼层,计算总共需要多少秒。

例子:上二楼需要12秒,再上一层6秒,下到1层8秒,每一层停留5秒一共15秒加起来:12+6+8+15=41。

题解:

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

1008 Elevator (20分)的更多相关文章

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

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

  2. 【PAT甲级】1008 Elevator (20分)

    1008 Elevator 题目: The highest building in our city has only one elevator. A request list is made up ...

  3. 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 ...

  4. PAT (Advanced Level) Practice 1008 Elevator (20 分) (模拟)

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

  5. 1008 Elevator (20 分)

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

  6. 【PAT甲级】1008 Elevator (20 分)

    题意: 电梯初始状态停在第0层,给出电梯要接人的层数和层序号,计算接到所有人需要的时间,接完人后电梯无需回到1层(1层不是0层).电梯上升一层需要6秒,下降一层需要4秒,接人停留时间为5秒. AAAA ...

  7. PAT 甲级 1008 Elevator (20)(代码)

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

  8. PAT 1008. Elevator (20)

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

  9. 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 ...

随机推荐

  1. 详解 LinkedHashMap

    同学们可能在看到这个类的时候就明白了很多关于这个类的特点,那么,本人就在这里来啰嗦一下,再来介绍下这个类: (有关Map集合的基本性质,请观看本人博文-- <详解 Map集合>) Link ...

  2. cmd命令行中查看、修改、删除与添加环境变量

    注意:只在当前窗口生效!! 1.查看当前所有可用的环境变量:输入 set 即可查看. set 2.查看某个环境变量:输入 “set 变量名”即可 set python 3.修改环境变量 :输入 “se ...

  3. Redis入门使用 -- 个人总结

    目录 什么是Redis? Redis 与其他 key - value 数据库的对比 Redis 能干什么 Redis的安装配置 Redis启动和连接 上面开启的是非守护线程下启动(独占模式),下面我们 ...

  4. [HTML] <base>链接默认打开方式标签元素

    HTML 超链接(锚文本)默认打开方式与默认链接URL地址标签元素 一.语法与结构 <base target="_blank" href="http://www.l ...

  5. React Hooks: use modal

    useModal: export const useModal = (initTitle: string, initContent: string | React.ReactElement) => ...

  6. 集合-ArrayList 源码解析

    ArrayList是一种以数组实现的List,与数组相比,它具有动态扩展的能力,因此也可称之为动态数组. 类图 ArrayList实现了List, RandomAccess, Cloneable, j ...

  7. JavaScript type="text/template"的用法

    JavaScript type="text/template"相当于定义一个模板,如果没有使用html()方法的话,是显示不出来的,我们直接看例子(我是在tp框架的里面写的) &l ...

  8. WANNACRY病毒中的加密技术分析

    WANNACRY病毒中的加密技术分析 2019/11/6 16:56:46 分析WANNACRY病毒中的加解密技术的应用.分析内容包括但不限于:对称密码技术和公钥密码技术的作用:受害者支付赎金后就会恢 ...

  9. 【ubuntu】windows+ubuntu 设置windows为第一启动项

    进入ubuntu系统 sudo su vim /etc/default/grub 更改GRUB_DEFAULT=后的值默认是0,如果你的windows启动项在第5个就改成4.改完之后退出保存输入 up ...

  10. css之颜色表示法

    css之颜色表示法 十六进制颜色 所有浏览器都支持十六进制颜色值. 十六进制颜色是这样规定的:#RRGGBB,其中的 RR(红色).GG(绿色).BB(蓝色)十六进制整数规定了颜色的成分.所有值必须介 ...