杭电 1008 Elevator
来源:互联网 发布:中国统计年鉴数据下载 编辑:程序博客网 时间:2024/06/05 08:08
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>using namespace std;int main(){int n;while(cin>>n&&n!=0){int floor[1000];floor[0]=0;int time=0;for(int i=1;i<=n;i++){cin>>floor[i];if(floor[i]>floor[i-1]){time+=6*(floor[i]-floor[i-1]);}else if(floor[i]<floor[i-1]){time+=4*(floor[i-1]-floor[i]);}time+=5;}cout<<time<<endl;}return 0;}
0 0
- 杭电1008 Elevator
- 杭电1008 Elevator
- 杭电1008 Elevator
- Elevator 杭电1008
- 杭电 1008 Elevator
- 杭电1008 Elevator
- 杭电 1008 Elevator
- 杭电 1008 Elevator
- 杭电1008-Elevator
- 杭电 1008 Elevator
- 杭电1008 Elevator
- 杭电ACM 1008Elevator
- 杭电ACM-1008 Elevator
- 杭电ACM-1008-Elevator
- 杭电acm 1008 Elevator
- 杭电 ACM 1008:Elevator
- 杭电ACM 1008Elevator
- 杭电 HDOJ 1008 Elevator
- java基础编程
- 【Linux】Ubuntu系统中codeblocks主题修改(护vim)
- 函数指针
- 二分、三分查找算法模板
- linux之hbase安装
- 杭电 1008 Elevator
- 程序复杂度估计的表示方法
- Java虚拟机类加载机制
- C/C++ 语言中的表达式求值
- 使用es6 proxy 自动监听对象
- 第六章 递归,内联,重载,作用域和存储类型
- 心理咨询预约如何在微信公众号如何快速实现
- freertos内核走读2——task任务调度机制(一)
- java锁之wait,notify(wait会释放锁,notify仅仅只是通知,不释放锁)(转)