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

题目描述:

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 个正整数组成。这些数字表示电梯将会在哪些指定楼层停靠。电梯上升一层花费 6 秒 的时间,电梯下降一层花费 4 秒的时间。电梯每次停靠会停留 5 秒的时间


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.

译:每个输入文件包含一个测试用例,每个用例包含一个整数 N , 紧跟着后面的是 N 个正整数。输入所有的数字都小于 100.


Output Specification (输出说明):

For each test case, print the total time on a single line.

译:对于每个测试用例,在一行中输出耗费时间的总和。


Sample Input (样例输入):

  1. 3 2 3 1

Sample Output (样例输出):

  1. 41

The Idea:

首先,有 N 个数据意味着需要停留 N 次,所以可以直接算出停留的时间就是 N * 5 , 然后再遍历列表中的所有数,如果是上升,结果就加上 楼层差乘以 6 秒,如果是下降,结果就加上 楼层差乘以 4 秒, 遍历结束,得到的总和就是答案。


The Codes:

  1. #include<bits/stdc++.h>
  2. using namespace std ;
  3. #define MAX 110
  4. int ele[MAX] = { 0 } ;
  5. int main(){
  6. int n , sum , t ;
  7. scanf("%d" , &n) ;
  8. sum = n * 5 ; // 所有的停靠时间
  9. for(int i = 1 ; i <= n ; i ++) scanf("%d" , &ele[i]) ;
  10. for(int i = 1 ; i <= n ; i ++){
  11. if(ele[i] > ele[i - 1]) sum += (ele[i] - ele[i - 1]) * 6 ; // 加上上升的时间
  12. else sum += (ele[i - 1] - ele[i]) * 4 ; // 加上下降的时间
  13. }
  14. printf("%d\n" , sum) ;
  15. return 0 ;
  16. }

PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642的更多相关文章

  1. PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642 题目描述: To prepare for PAT, the judge someti ...

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

  3. PAT (Advanced Level) Practice 1035 Password (20 分)

    To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem ...

  4. 【PAT Advanced Level】1008. Elevator (20)

    没什么难的,简单模拟题 #include <iostream> using namespace std; int main() { int num; cin>>num; int ...

  5. PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642 题目描述: The task is really simple: ...

  6. PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642 题目描述: Shuffling is a procedure us ...

  7. PAT (Advanced Level) Practice 1041 Be Unique (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1041 Be Unique (20 分) 凌宸1642 题目描述: Being unique is so important to peo ...

  8. PAT (Advanced Level) Practice 1031 Hello World for U (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1031 Hello World for U (20 分) 凌宸1642 题目描述: Given any string of N (≥5) ...

  9. PAT (Advanced Level) Practice 1027 Colors in Mars (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1027 Colors in Mars (20 分) 凌宸1642 题目描述: People in Mars represent the c ...

随机推荐

  1. CSS Shapes

    CSS Shapes shape-outside & shape-image-threshold <img class="element" src="ima ...

  2. 两百万SPC空投来袭,带动市场热情!

    NGK投放项目的时间节点总是以牛市为主,像是上一次的BGV项目投放就在2020年末的数字加密货币牛市,其结果想必各位生态建设者们都已经见到了,在登陆交易所首日便高收于近889美金,创下惊人的近一千七百 ...

  3. 【PY从0到1】 一文掌握Pandas量化进阶

    # 一文掌握Pandas量化进阶 # 这节课学习Pandas更深的内容. # 导入库: import numpy as np import pandas as pd # 制作DataFrame np. ...

  4. 基本ILS面的评估

    一.定义与用途 基本ILS面是ICAO DOC8168飞行程序设计规范中提到的一种限制面. 它相当于附件14中代码为3或4的精密进近跑道所规定的障碍物限制面的子集. 包含:进近面(分为两部分).过渡面 ...

  5. 让 gRPC 提供 REST 服务

    让 gRPC 提供 REST 服务 Intro gRPC 是一个高性能.开源和通用的 RPC 框架,面向移动和 HTTP/2 设计. gRPC 基于 HTTP/2 标准设计,带来诸如双向流.流控.头部 ...

  6. 使用RSEM进行转录组测序的差异表达分析

    仍然是两年前的笔记 1. prepare-reference 如果用RSEM对比对后的bam进行转录本定量,则在比对过程中要确保比对用到的索引是由rsem-prepare-reference产生的. ...

  7. now-go时间百宝箱

    golang不像C#,Java这种高级语言,有丰富的语法糖供开发者很方便的调用.所以这便催生出很多的开源组件,通过使用这些第三方组件能够帮助我们在开发过程中少踩很多的坑. 时间处理是所有语言都要面对的 ...

  8. 开源OA办公平台搭建教程:O2OA表单中的事件

    1. 概述 我们设计表单的时候经常会有这样的需求:在表单或者组件加载前/加载后,能够执行一些脚本来改变表单或组件的样式和行为.或者用户在点击组件的时候能够执行脚本.表单的事件就是为这样的场景而设计. ...

  9. 你真的懂 MP4 格式吗?

    MP4 文件格式又被称为 MPEG-4 Part 14,出自 MPEG-4 标准第 14 部分 .它是一种多媒体格式容器,广泛用于包装视频和音频数据流.海报.字幕和元数据等.(顺便一提,目前流行的视频 ...

  10. 【Azure 服务总线】Azure Service Bus中私信(DLQ - Dead Letter Queue)如何快速清理

    在博文ServiceBus 队列中死信(DLQ - Dead Letter Queue)问题一文中,介绍了服务总线产生私信的原因及可以通过代码的方式来清楚私信队列中的消息,避免长期占用空间(因为私信中 ...