Elevator
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 Specification:
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.
Output Specification:
For each test case, print the total time on a single line.
Sample Input:3 2 3 1Sample Output:
41
1 /* 2 * File: main.cpp 3 * Author: zjushuiping 4 * 5 * Created on 2012年4月11日, 上午12:13 6 */ 7 8 #include <cstdlib> 9 #include <iostream> 10 #include <cstdio> 11 #include <vector> 12 #include <cmath> 13 #include <cstring> 14 #include <cctype> 15 #include <list> 16 #include <deque> 17 #include <stack> 18 #include <queue> 19 #include <map> 20 #include <set> 21 #include <string> 22 #include <algorithm> 23 24 25 using namespace std; 26 27 28 29 30 31 32 /* 33 * 34 */ 35 36 37 int floors[1000+4]; 38 39 40 int main(int argc, char** argv) { 41 42 int n; 43 int i,j,k; 44 45 scanf("%d",&n); 46 47 48 int sum=0; 49 50 sum+=n*5; 51 52 for(i=1;i<=n;i++) 53 { 54 scanf("%d",&floors[i]); 55 } 56 57 floors[0]=0; 58 59 60 for(i=1;i<=n;i++) 61 { 62 int ans=floors[i]-floors[i-1]; 63 if(ans>0) 64 { 65 sum+=ans*6; 66 } 67 else 68 { 69 sum+=-1*ans*4; 70 } 71 } 72 73 74 printf("%d\n",sum); 75 76 77 78 79 80 81 return 0; 82 }