电梯用时
来源:互联网 发布:书生空谈 知乎 编辑:程序博客网 时间:2024/04/28 11:11
Elevator
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 63717 Accepted Submission(s): 35065
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.
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
#include<iostream>#include<stdio.h>using namespace std;int main(void){int n,m,last,sum;while(scanf("%d",&n) != EOF){last = 0;sum = 0;if(n == 0)break;while(n--){cin>>m;if(m>last)sum+=((m-last)*6+5);elsesum+=((last-m)*4+5);last = m;}printf("%d\n",sum);}return 0;}
0 0
- 电梯用时
- 电梯
- 电梯
- 电梯
- 电梯
- 电梯
- 电梯
- 电梯
- 电梯
- 电梯
- 电梯、电梯调度与电梯问题
- 电梯控制程序
- 电梯算法
- 电梯算法
- 电梯惊魂
- 电梯惊魂
- 电梯问题
- 电梯算法
- 19.小学生算术
- 打造专属的Chromium for Android
- invalidate()不起作用
- OkHttp源码解析(三)——连接池复用
- 20.日期计算
- 电梯用时
- log4j.properties 配置详解
- iOS之UIViewController执行返回操作并传递参数值的两种方式
- 21.开灯问题
- 22.n-1位数
- 基于javase的通讯录项目
- Tyvj P1015 公路乘车
- [Android]Android 开发环境下载地址 -- 百度网盘 adt-bundle android-studio sdk adt 下载
- sort qsort 用法总结