欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

(杭电 1008 电梯问题)Elevator

程序员文章站 2022-06-05 16:04:51
Elevator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 30095 Accepted Submission(s): 16272 Prob ......

elevator

time limit: 2000/1000 ms (java/others) memory limit: 65536/32768 k (java/others)total submission(s): 30095 accepted submission(s): 16272

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

水题(话说有这么zz的电梯吗23333)

代码样例

#include <stdio.h>

int main() {
    int t;
    while (scanf("%d",&t) != eof,t != 0) {
        int time=0,temp=0;
        for(int i=0; i < t; i++) {
            int n;
            scanf("%d",&n);
            if(temp < n) {
                time=time+(n-temp)*6;
                temp=n;
            }
            if(temp > n) {
                time=time+(temp-n)*4;
                temp=n;
            }
            if(temp == n)
                time=time+5;
        }
        printf("%d\n",time);
    }
    return 0;
}