PAT A 1008. Elevator (20)
来源:互联网 发布:变形金刚玩具淘宝 编辑:程序博客网 时间:2024/05/22 03:18
原题
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
直接模拟即可
代码:
#include <iostream>using namespace std;int main(){int n,floor_next,floor_at=0,time=0;//n,下一层,所在层int i,j;cin>>n;for(i=0;i<n;i++){cin>>floor_next;if(floor_next>floor_at){time+=6*(floor_next-floor_at)+5;floor_at=floor_next;}else{time+=4*(floor_at-floor_next)+5;floor_at=floor_next;}}cout<<time;return 0;}
- PAT A 1008. Elevator (20)
- PAT(A) - 1008. Elevator (20)
- PAT A 1008. Elevator (20)
- PAT-A 1008. Elevator (20)
- PAT-A-1008. Elevator (20)
- PAT-A 1008. Elevator (20)
- PAT-A 1008. Elevator
- 1008. Elevator (20)-PAT
- 【PAT】1008. Elevator (20)
- PAT 1008. Elevator (20)
- PAT 1008. Elevator (20)
- PAT 1008. Elevator (20)
- PAT 1008. Elevator (20)
- pat 1008. Elevator (20)
- PAT 1008. Elevator (20)
- PAT 1008. Elevator (20)
- PAT甲 1008. Elevator (20)
- 【PAT甲级】1008. Elevator (20)
- .net中用arcgis engine对象、AO接口类型声明属性,报错"new void()"
- win7下安装python
- 第十一周项目1-1-存储班长信息的学生类(protect)
- 移动开发之iOS基础开发(二)实现基本的简单交互
- 喜则气和顺而志意畅达
- PAT A 1008. Elevator (20)
- HDU_2074叠筐
- python学习日志<一>
- 直接拿来用!最火的Android开源项目(二)
- keepalived配置
- 《Android Design》 4.4 中文版 .
- 网页开发预览附件
- 前台字段绑定,变量绑定
- android EditText 设置密码锁源码