我现在做的是百
Problem G
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 129 Accepted Submission(s) : 76
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.
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分钟,计算乘坐电梯要花费的时间。 解题思路:通过向量容器记录电梯运行的经过,通过判断相邻两次运行后时的楼层的大小,计算花费的时间,最后,加上电梯停止时要等待的时间,就是最终要花费的时间。 编写代码: #include <iostream> #include <vector> using namespace std; int main() { vector<int> v; int n; while ( cin >> n) { if (n == 0) break; else { int t; for (int i=0; i<n; i++) { cin >> t; v.push_back(t); } int times = 0; int floor = 0; for (int j=0; j<n; j++) { if ((v[j] - floor) > 0) { times += (v[j] - floor) * 6 ; floor = v[j]; } else { times += (floor - v[j]) * 4; floor = v[j]; } } cout << times + n * 5 << endl; v.clear(); } } return 0; }