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.ios
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.less
Input Specification:ui
Each input file contains one test case. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100.spa
Output Specification:code
For each test case, print the total time on a single line.blog
Sample Input:ci
3 2 3 1
Sample Output:input
在一座高樓上只有一個電梯,而後有 n 個電梯將要中止的樓層 電梯上升一層 用時 6 秒 , 降低一層用時 4 秒, 在每層中止時 停下5秒
初始位置爲 0 層, 當電梯中止在最後一個位置後再也不返回 0 層
問 電梯須要多長時間完成 n 個任務請求
41
#include <iostream> #include <algorithm> using namespace std; #define maxn 200 int n , floors[maxn] ; int main(){ while(cin >> n ){ for(int i=1 ; i<=n ; i++){ cin >> floors[i] ; } int sum = 0 ; floors[0] = 0 ; // 第 0 層 for(int i=1 ; i<=n ; i++){ if(floors[i] - floors[i-1] >= 0 ){ // 上升 sum += (floors[i] - floors[i-1]) * 6 ; }else { // 降低 sum += abs(floors[i] - floors[i-1]) * 4 ; } } sum += n * 5 ; // 每層樓中止時 停下 5 秒 cout << sum << endl ; } return 0 ; }