1008 Elevator

分数 20

全屏浏览题目

切换布局

作者 CHEN, Yue

单位 浙江大学

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秒;

思路:用to代表要去的楼层,now代表现在的楼层,to比now大就是上楼,比now小就是下楼,不管上楼还是下楼都要等5秒,从而得出总时间;

代码:

#include<iostream>
using namespace std;
int main(){int n,to,now=0,cost=0;cin>>n;for(int i=0;i<n;i++){cin>>to;to>now?cost+=(to-now)*6:cost+=(now-to)*4;cost+=5;now=to;}cout<<cost;
} 

pat 甲级 A1008 Elevator相关推荐

  1. PAT甲级1008 Elevator:[C++题解]模拟

    文章目录 题目分析 题目来源 题目分析 来源:acwing 分析:统计上升次数.下降次数:停留次数就是n.然后算数即可. ac代码 #include<bits/stdc++.h> usin ...

  2. 【PAT甲级】A1001-A1050刷题记录

    文章目录 A1001 A+B Format (20 分) 0.25 ★(一元多项式加法) A1002 A+B for Polynomials (25 分) 0.21 (单源最短路Dijkstra+边权 ...

  3. PAT甲级训练合集(1-70)

    本章题解跳转 考点 P1001 数字的数组表示和处理 P1002 多项式的数组表示和处理 P1003 深度优先搜素 P1004 深度优先搜素 P1005 哈希表 P1006 P1007 数组子区间求和 ...

  4. 【PAT】PAT甲级题库所有题解(持续更新中...)

    题解: 本文为导航页,一些希望刷PAT甲级的玩家可以来看看,我会持续更新所有题目的题解(取决于我做到哪儿了(doge)) 题号按照PAT官网给出的标注 题目: 链接 标签 1001 A+B Forma ...

  5. PAT甲级1001~1025

    PAT甲级1001~1025 1001 A+B Format (20 分) 1002 A+B for Polynomials (25 分) 1003 Emergency (25 分) 1004 Cou ...

  6. 【置顶】【PAT】PAT甲级题目及分类总结(持续更新ing)

    在2019年3月底,我决定考浙大计院,经过一个月还算凑合的学习,痛定思痛,决定整理整理自己的博客. 粗略估计,大概一个月的时间里我AC了31道题,大概用时40个小时上下,毕竟还要把大部分时间花在笔试上 ...

  7. PAT甲级(Advanced Level)真题--1046 Sharing

    PAT甲级(Advanced Level)真题–1046 Sharing 通过:648 提交:1138 通过率:56% To store English words, one method is to ...

  8. PAT甲级(Advanced Level)真题-- 1062 To Buy or Not to Buy

    PAT甲级(Advanced Level)真题-- 1062 To Buy or Not to Buy 通过:643 提交:1220 通过率:52% Eva would like to make a ...

  9. PAT甲级真题 1018 A+B in Hogwarts--python解法

    PAT甲级真题 1018 A+B in Hogwarts 提交:2638 通过:1559 通过率:59% If you are a fan of Harry Potter, you would kno ...

最新文章

  1. UVA 10041 Vito's Family
  2. linux-----shell高级编程----sed应用
  3. iOS 动画基础总结篇
  4. 2018 ACM-ICPC World Finals - Beijing
  5. php有几种数据结构,PHP数据结构有几种_后端开发
  6. 关于直播,所有的技术细节都在这里了(二)
  7. Ubuntu下利用Wine安装AxureRP 8
  8. leach算法的实现过程_LEACH分簇算法实现和能量控制算法实现(示例代码)
  9. 非360手柄玩游戏视角颠倒的解决方案
  10. android assets绝对路径,Android获取assets文件路径
  11. Postgresql 配置远程访问
  12. Linux从入门到实战 ---- 磁盘分区
  13. 网站 502 解决方法
  14. TiDB 5.0 HTAP 架构设计与场景解析
  15. Hawk-数据抓取工具:简明教程
  16. 苹果ppt_最近苹果新机的3个动画霸屏了,PPT制作竟如此简单,手把手教你做出来!...
  17. 91.p58.space http://email.91dizhi.at.gmail.com06监测模块测试入口index.php
  18. CSDN做测试的老师教你Jmeter生成压力测试报告
  19. 从C++起步到MFC实战VC++软件工程师高端培训(服务器端开发方向)学习课程
  20. 360浏览器html5脚本,360浏览器运行脚本易培训

热门文章

  1. 使用 Learner Lab 建立 WordPress 网站 (EC2)
  2. 网络数据保障ptop_网络影响未来十大预言 宽带应用将与新媒体融合
  3. RT-Thread Studio配置连接WIFI模块
  4. oa系统需要的服务器配置,oa办公系统需要服务器配置
  5. NETSDK1045 当前 .NET SDK 不支持将 .NET 6.0 设置为目标。请将 .NET 5.0 或更低
  6. svn怎么执行清理命令_win7系统如何清理注册表 win7系统清理注册表方法【介绍】...
  7. Android中的传感器之---光线传感器
  8. Java实现 LeetCode 93 复原IP地址
  9. 如何修改 gitlab 的项目名称
  10. 利用Python检验用户输入密码的复杂度,非常简单