hdu1008

返回“大学生程序设计竞赛”

Elevator

http://acm.hdu.edu.cn/showproblem.php?pid=1008

/*written by czk*/
#include <stdio.h>

int main() {
    int n, i;
    while(scanf("%d", &n) != EOF) {
        int time = 0;
        int current = 0;
        int next;
        if(n == 0)
            break;
        for(i = 0; i < n; i++) {
            scanf("%d", &next);
            if(next > current)
                time += (next - current) * 6 + 5;
            else
                time += (current - next) * 4 + 5;
            current = next;
        }
        printf("%d\n", time);
    }
}