PTA (Advanced Level) 1008 Elevator
Elevator
The highest building in our city has only one elevator. A request list is made up with Npositive 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 Npositive 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
题目解析
本题首先给出一个整数n代表电梯会停留的层数,之后给出n个数,代表电梯具体停留的楼层,电梯初始在0层,每向上一层会消耗6秒,每向下一层会消耗4秒,在需停留层会停留5秒,电梯最后不需要返回0层。
模拟一下电梯的运行过程即可。
- #include <bits/stdc++.h>
- using namespace std;
- int n, t = , nowf = ; //n为电梯需停留层数, t为已经消耗的时间, nowf是电梯当前所在的楼层
- int main()
- {
- scanf("%d", &n); //输入电梯需停留层数
- while(n--){
- int floors;
- scanf("%d", &floors); //输入下一个要停留的楼层
- while(nowf < floors){ //向上运行
- nowf++;
- t += ;
- }
- while(nowf > floors){ //向下运行
- nowf--;
- t += ;
- }
- t += ; //停留
- }
- printf("%d\n", t);
- return ;
- }
PTA (Advanced Level) 1008 Elevator的更多相关文章
- PAT (Advanced Level) 1008. Elevator (20)
简单模拟. 注意a[i]==a[i-1]的情况. #include<iostream> #include<cstring> #include<cmath> #inc ...
- PTA(Advanced Level)1036.Boys vs Girls
This time you are asked to tell the difference between the lowest grade of all the male students and ...
- PTA (Advanced Level) 1004 Counting Leaves
Counting Leaves A family hierarchy is usually presented by a pedigree tree. Your job is to count tho ...
- PTA (Advanced Level) 1020 Tree Traversals
Tree Traversals Suppose that all the keys in a binary tree are distinct positive integers. Given the ...
- PTA(Advanced Level)1025.PAT Ranking
To evaluate the performance of our first year CS majored students, we consider their grades of three ...
- PTA (Advanced Level) 1009 Product of Polynomials
1009 Product of Polynomials This time, you are supposed to find A×B where A and B are two polynomial ...
- PTA (Advanced Level) 1007 Maximum Subsequence Sum
Maximum Subsequence Sum Given a sequence of K integers { N1, N2, ..., NK }. A continuous su ...
- PTA (Advanced Level) 1006 Sign In and Sign Out
Sign In and Sign Out At the beginning of every day, the first person who signs in the computer room ...
- PTA (Advanced Level) 1005 Spell It Right
Spell It Right Given a non-negative integer N, your task is to compute the sum of all the digits of ...
随机推荐
- 1.mybatis入门
一:创建表 CREATE TABLE `country` ( `id` ) NOT NULL AUTO_INCREMENT, `countryname` varchar() DEFAULT NULL, ...
- 雪花算法(snowflake)delphi版
雪花算法简单描述: + 最高位是符号位,始终为0,不可用. + 41位的时间序列,精确到毫秒级,41位的长度可以使用69年.时间位还有一个很重要的作用是可以根据时间进行排序. + 10位的机器标识,1 ...
- php支持连接sqlserver数据库
php支持连接sqlserver数据库 1.软件配置 Win7 64 +wampserver2.2d-x32+SQL Server 2008 R2数据库,wamp2.2中的php版本是5.3.10. ...
- [Leedcode 169]Majority Element
1 题目描述 Given an array of size n, find the majority element. The majority element is the element that ...
- java并发的处理方式
1 什么是并发问题. 多个进程或线程同时(或着说在同一段时间内)访问同一资源会产生并发问题. 银行两操作员同时操作同一账户就是典型的例子.比如A.B操作员同时读取一余额为1000元的账户,A操作员为该 ...
- ELK冷热数据分离
通常情况下,我们使用ELK日志分析平台最常用的数据时间为1周或一个月(因业务场景不同,可能存在差别),时间比较长的数据没有特殊情况可能我们就没有必要再进行查询了,但是因业务需求或者作为凭证,这些日 ...
- .Net Core Razor 预编译,动态编译,混合编译
预编译 预编译是ASP .Net Core的默认方式.在发布时,默认会将系统中的所有Razor视图进行预编译.编译好的视图DLL统一命名为 xxx.PrecompiledViews.dll 或者 xx ...
- .net中的SelectList在Html.DropdownList中的使用
.net中的SelectList可以用于前端下拉框的内容填充 譬如:Html.DropdownList(下拉框标签名称, SelectList实例) 实际上,上述Html.DropdownList的第 ...
- UWP开发---抓包分析
一,使用工具 ①Fiddler 摘自百度百科Fiddler简介: Fiddler是一个http协议调试代理工具,它能够记录并检查所有你的电脑和互联网之间的http通讯,设置断点,查看所有的“进出”Fi ...
- AEAI DP开发统计分析
1 背景概述 平时做统计分析都是调rest服务,给前台提供数据,然后在管理控制台里配置portlet.但并不是所有的项目都会用到portal,这时就需要在AEAI DP应用开发平台里开发统计分析了,下 ...