HDU1008
来源:互联网 发布:通达信短线决策源码 编辑:程序博客网 时间:2024/06/05 02:05
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 2
3 2 3 1
0
Sample Output
17
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
乘电梯,每升一层需要6秒,下降一层需要4秒,停留一层需要5秒,电梯从0层开始,输入一串数字,代表所需停留的楼层,
求电梯运行完的时间。
#include<iostream>using namespace std;int main(){int s[110], n;int total,t;while (cin >> n&&n!=0){total = 0;memset(s,0, sizeof(0));for (int i = 0; i < n; i++)cin >> s[i];total =total+ (s[0] * 6 + 5);for (int i = 1; i < n; i++){if (s[i] > s[i - 1]){t = s[i] - s[i - 1];total +=( t * 6 + 5);}else{t = s[i - 1] - s[i];total += (t * 4 + 5);}}cout << total << endl;}}
0 0
- hdu1008
- hdu1008
- hdu1008
- hdu1008
- HDU1008
- HDU1008
- HDU1008
- hdu1008
- hdu1008
- HDU1008
- hdu1008
- HDU1008
- HDU1008
- HDU1008
- HDU1008
- HDU1008
- hdu1008
- HDU1008 Elevator
- uml九种图之用例图 构建图
- nginx location alias 和 root 差别
- 第5周 项目3 - 括号的匹配(2)
- 二分
- Java中final、finally 和 finalize 的区别
- HDU1008
- C++中的to_string()函数[C++11支持]
- Jar包混淆后引用报错
- 嵌入式Linux网络编程
- 2016 ccpc(长春站) 一个弱鸡的总结
- HDU 3555 Bomb(数位DP)
- latex表格
- 机器学习简单思想梳理
- SDNU 1311.Binomial Coeffcients 杨辉三角算组合数