本文主要是介绍【PAT】【Advanced Level】1008. Elevator (20),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1008. Elevator (20)
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
原题链接:
https://www.patest.cn/contests/pat-a-practise/1008
思路:
模拟即可
代码:
#include<iostream>
using namespace std;
int main()
{int n;cin>>n;int s=0;int re=0;for (int i=0;i<n;i++){int a;cin>>a;if (a>s){re+=6*(a-s);}else{re+=4*(s-a);}re+=5;s=a;}cout<<re;return 0;
}
这篇关于【PAT】【Advanced Level】1008. Elevator (20)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!