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 ...
随机推荐
- (最长不降子序列)最少拦截系统 -- hdu -- 1257
http://acm.hdu.edu.cn/showproblem.php?pid=1257 最少拦截系统 Time Limit: 2000/1000 MS (Java/Others) Memo ...
- (最长上升子序列 并记录过程)FatMouse's Speed -- hdu -- 1160
http://acm.hdu.edu.cn/showproblem.php?pid=1160 FatMouse's Speed Time Limit: 2000/1000 MS (Java/Other ...
- GPT分区在IBM服务器上安装linux不能引导的解决方法
提示: Your boot partition is on a disk using the GPT partitioning Scheme but this machines cannot boot ...
- POJ1446 Girls and Boys
Girls and Boys Time Limit: 5000MS Memory Limit: 10000K Total Submissions: 12747 Accepted: 5678 D ...
- 怎样去写线程安全的代码(Java)
使用多线程就可能会存在线程安全的问题.很多 java 程序员对写多线程都很挣扎,或者仅仅理解那些是线程安全的代码,那些不是.这篇文章我并不是详述线程安全,详述同步机制的文章,相反我只是用一个简单的非线 ...
- hdu 5060 五种情况求圆柱体与球体交
http://acm.hdu.edu.cn/showproblem.php?pid=5060 官方题解http://bestcoder.hdu.edu.cn/给复杂了 实际上用圆柱体与球体体积差的积分 ...
- Android-okhttp下载网络图片并设置壁纸
在AndroidManifest.xml配置网络访问权限: <!-- 访问网络是危险的行为 所以需要权限 --> <uses-permission android:name=&quo ...
- [ASE][Daily Scrum]11.07-11.09
周五-周日的任务计划统一布置了,在昨天我们已经将所有开发环境.开发工具.以及服务器问题敲定,接下来就是整个游戏的框架以及细节实现,首先打算在本周末将各个部分的通信接口确定下来,这样之后大家就可以专注于 ...
- Apollo 配置详细步骤(Windows环境)
一. 准备工作 1.下载 apollo 安装包 下载链接:http://activemq.apache.org/apollo/download.html 2.下载 JavaJDK 安装包 ( apol ...
- C#中类的属性的获取
/// <summary> /// 将多个实体转换成一个DataTable /// </summary> /// <typeparam name="T" ...