hdu 1008 Elevator

Elevator

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 52791    Accepted Submission(s): 29174


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 2
3 2 3 1
0
 

 

Sample Output
17
41
 

 

Author
ZHENG, Jianqiang
 

 

Source
 

 

Recommend
JGShining   |   We have carefully selected several similar problems for you:  1071 1170 1006 1007 1032 
 
数学水题,特别简单
 
题意:在我们城市里,有一个最高的大楼,可是这个大楼只有一个电梯。现在有一个由N个正整数组成请求列表,表示一群人要到达的楼层。而这个电梯要花6秒钟时间上升一层,4秒钟时间下降一层,每层楼的停留时间为5秒钟。对于给出的请求列表,要让那群人达到各自的楼层,总共要花多少时间呢?求出这个时间。假设电梯一开始事在0层,当把人送完后并不需要回到0层。
 
附上代码:
 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4 int main()
 5 {
 6     int n,m,i,j;
 7     while(~scanf("%d",&n)&&n)
 8     {
 9         int sum=0,t=0;
10         while(n--)
11         {
12             scanf("%d",&m);
13             if(m>t)       //上楼
14                 sum=sum+(m-t)*6;
15             else          //下楼
16                 sum=sum+(t-m)*4;
17             sum+=5;       //每次停留需要5秒
18             t=m;
19         }
20         printf("%d\n",sum);
21     }
22 }

 

 
posted @ 2015-08-26 14:00  lucky_少哖  阅读(228)  评论(0编辑  收藏  举报