HDU:1008 Elevator
来源:互联网 发布:json value processor 编辑:程序博客网 时间:2024/05/19 12:39
Elevator
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 65952 Accepted Submission(s): 36302
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>#include <string.h>#include <algorithm>using namespace std;int a[100004];int main(){ int N,i; while(~scanf("%d",&N)) { if(N == 0) break; int time = 0; a[0] = 0; for(i = 1; i <= N; i++) { scanf("%d",&a[i]); if(a[i]>a[i-1]) { time += (a[i]-a[i-1])*6+5; } else if(a[i]<a[i-1]) { time += (a[i-1]-a[i])*4+5; } else { time = time + 5; } } printf("%d\n",time); } return 0;}
0 0
- HDU 1008 Elevator
- hdu 1008Elevator
- HDU 1008 Elevator
- HDU 1008 Elevator
- hdu 1008 elevator 水
- HDU 1008 Elevator
- Hdu 1008 - Elevator
- HDU 1008 Elevator
- HDU--1008--Elevator
- hdu 1008 Elevator
- HDU-1008 Elevator
- HDU 1008 Elevator
- hdu 1008 Elevator
- Hdu--1008--Elevator
- hdu 1008 Elevator
- hdu 1008 Elevator
- hdu-1008-Elevator
- hdu 1008 Elevator
- 10.23
- HTML—基础
- 3-5 学生成绩统计
- AngularJS之默认样式
- java反射 java.lang.IllegalArgumentException: wrong number of arguments
- HDU:1008 Elevator
- Java熟悉到陌生之线程之Callable接口
- Android中.9图片的含义及制作教程
- HDU 4287 Intelligent IME(字符串)
- 3-6 静态数据成员与静态成员函数
- java之poi操作excel-基本的excel读写操作
- 双缓冲技术
- js面试题
- 我的MacOS上的软件