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>


 

0 0