HDU1008

来源:互联网 发布:手机闪光灯软件下载 编辑:程序博客网 时间:2024/06/16 22:03

Elevator



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
//HDU1008 基础题//Elevator//2017.05.23 by wyj#includeusing namespace std;int main(){int floor[1000];int n;int i;int t;floor[0] = 0;do {cin >> n;for (i = 1, t = 0;i <= n;i++){cin >> floor[i];if (floor[i] > floor[i - 1])t += (6 * (floor[i] - floor[i - 1]) + 5);else if (floor[i] < floor[i - 1])t += (4 * (floor[i - 1] - floor[i]) + 5);elset += 5;} if (n != 0)cout << t << endl;} while (n != 0);return 0;}
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 小孩在家里偷钱怎么办 脾气不好的猫该怎么办 二年孩子偷钱怎么办 孩子偷钱2000报警怎么办? 我儿子十岁老是偷钱怎么办 13孩子偷同学钱怎么办 孩子偷同学的钱怎么办 儿子十四岁了老偷钱怎么办 发现初中生的儿子偷钱怎么办 被亲戚怀疑儿子偷钱怎么办 房门选的太白了怎么办 大厅地砖颜色比墙砖浅怎么办 房屋外墙渗水物业不管怎么办 走丢了怎么办教学反思 托班教案迷路了怎么办 大班安全教案遇到小偷怎么办 小班孩子舞台表演找不到位置怎么办 懂你英语学完了怎么办 小班社会走丢了怎么办 帮小老鼠搬鸡蛋怎么办 小老鼠还能怎么办鸡蛋 中班教案走丢了怎么办 走丢了怎么办可后反思 社会走丢了怎么办教案 孩子一直不吃幼儿园的饭怎么办 大班安全游泳抽筋怎么办反思 汤洒了怎么办教学反思 迷路了怎么办小班详案 大班牙又痛又摇怎么办 大班安全教案着火了怎么办 小班社会生病了怎么办反思 脚扭伤了怎么办的反思 中班安全迷了眼怎么办 15个月的小孩长泡疹怎么办 墨盒加错颜色墨水怎么办 墨盒颜色加错了怎么办 uV打印有色差是怎么办 cmyk和rgb有色差怎么办 染头发新长出来怎么办 白色衣服弄上口红怎么办 口红弄到牛仔裤上怎么办