1008 Elevator (20分)
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分)的更多相关文章
- PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642
PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642 题目描述: The highest building in our city has ...
- 【PAT甲级】1008 Elevator (20分)
1008 Elevator 题目: The highest building in our city has only one elevator. A request list is made up ...
- 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 ...
- 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 ...
- 1008 Elevator (20 分)
The highest building in our city has only one elevator. A request list is made up with N positive nu ...
- 【PAT甲级】1008 Elevator (20 分)
题意: 电梯初始状态停在第0层,给出电梯要接人的层数和层序号,计算接到所有人需要的时间,接完人后电梯无需回到1层(1层不是0层).电梯上升一层需要6秒,下降一层需要4秒,接人停留时间为5秒. AAAA ...
- PAT 甲级 1008 Elevator (20)(代码)
1008 Elevator (20)(20 分) The highest building in our city has only one elevator. A request list is m ...
- PAT 1008. Elevator (20)
1008. Elevator (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The highest ...
- 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 ...
随机推荐
- 散列表和JAVA中的hash
引文 hello,今天写的数据结构是散列表(hash表),也算是一种基础数据结构了吧.学过计算机的人大概都能说出来这是个以空间换时间的东西,那么具体怎么实现的是今天要讨论的问题. 为什么需要它?主要还 ...
- Springboot:配置文件位置以及多环境配置(六)
配置文件位置 Springboot配置文件可以加载以下四个位置: file:./config/ #第一加载位置 file:./ #第二加载位置 classpath:/config/ #第三加载位置 c ...
- gojs去水印
重点在go.js文件中将这个方法中的代码注释掉即可 搜索关键字 7ca11abfd022028846 然后注释下列代码,注释前先整理JS格式 function ni() { if(th) { var ...
- [Python进阶].pyc的那点事
1. 什么是 .pyc文件 .pyc文件 就是 Python的字节码(byte-compiled)文件..py文件运行时,python会自动将其编译成PyCodeObject并写入.pyc文件,再有p ...
- Python中实现按顺序遍历字典
第一种方法: import collections d = collections.OrderedDict([('a',1),('b',2),('c',3)]) ''' 或者把上面的那一行改成: d ...
- thinkphp5 不使用form,用input+ajax异步上传图片
不支持$this->request->file()获取图片 后台接收文件请使用$_FILE 正文开始: HTML <div class="upload"> ...
- 解决laravel5.4视图不生效的坑
遇到这种坑,主要是路由的问题 1.看看是不是单词拼错了 Route::get('/posts/{post}','\App\Http\Controllers\PostController@show'); ...
- ip的运用
1------获取ip$ip=$_SERVICE['REMOTE_ADDR'];2------根据ip获取主机名gethostbyaddr($ip);3------根据主机名获取IPgethostby ...
- java 8 stream reduce详解和误区
目录 简介 reduce详解 总结 java 8 stream reduce详解和误区 简介 Stream API提供了一些预定义的reduce操作,比如count(), max(), min(), ...
- Phaser都不懂,还学什么多线程
前面的文章中我们讲到了CyclicBarrier.CountDownLatch的使用,这里再回顾一下CountDownLatch主要用在一个线程等待多个线程执行完毕的情况,而CyclicBarrier ...