1408201941-hd-Elevator.cpp
来源:互联网 发布:网络众筹 编辑:程序博客网 时间:2024/04/29 04:55
Elevator
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4333 Accepted Submission(s): 2170
Problem Description
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
There are multiple test cases. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100. A test case with N = 0 denotes the end of input. This test case is not to be processed.
Output
Print the total time on a single line for each test case.
Sample Input
1 23 2 3 10
Sample Output
1741
题目大意
这是一个关于电梯的问题。电梯每次都是从0层开始,向上每一层花的时间6,向下每一层花的时间为4,电梯在每一层需要停止的楼层会停留5,求经过所有需要停留的楼层之后所用的总时间。
注意事项
结束的时间并不是电梯到达最后一个需要停留的楼层的时候,还需要再加上在最后一个需要停留的楼层停留所用的时间5.
代码
<span style="font-size:18px;">#include<stdio.h>int s[110];int main(){ int n; int i,j,k,sum; while(scanf("%d",&n),n) { for(i=0;i<n;i++) scanf("%d",&s[i]); sum=n*5; j=0; for(i=0;i<n;i++) { if(s[i]>j) sum+=(s[i]-j)*6; else if(s[i]<j) sum+=(j-s[i])*4; j=s[i]; } printf("%d\n",sum); } return 0;}</span>
- 1408201941-hd-Elevator.cpp
- HD-1008 Elevator 试题分析
- 1407261645-hd-密码.cpp
- 1407291712-hd-三角形.cpp
- 1408010808-hd-大菲波数.cpp
- 1408011500-hd-N!.cpp
- 1408071108-hd-Milk.cpp
- 1408140917-hd-Bitset.cpp
- 1408182100-hd-ASCII.cpp
- 1408201651-hd-GPA.cpp
- 1408202033-hd-最小公倍数.cpp
- 1408211519-hd-排序.cpp
- 1407230827-hd-数值统计.cpp
- 1407230852-hd-偶数求和.cpp
- 1407231800-hd-反素数.cpp
- 1407231857-hd-Problem A .cpp
- 1407231901-hd-Problem C.cpp
- 1407231910-hd-Problem E.cpp
- catalan卡特兰数
- 我的安卓之旅----启航
- Libgdx的使用(12)——physics-body-editor
- 上传文件到服务器方式之一:使用InputFile的ValueChangeListener
- MediaPlayer本地播放流程解析(二)
- 1408201941-hd-Elevator.cpp
- 上传文件到服务器方式之二:使用Button的ActionListener
- 如何实现下载文件之一:静态文件
- JsonUtil工具类
- vim中ctrl+z,jobs,fg命令用法
- 如何实现下载文件之二:动态文件
- C 与 C++ 的混合编程
- 在JAVA中使用DES算法
- 高版本Chrome扩展程序强制停止问题