首页 > 代码库 > 1008. Elevator (20)(模拟题)
1008. Elevator (20)(模拟题)
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 1
Sample Output:
41
Code:
1 #include <bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 int n , now , next , ans; 6 now = next = ans = 0; 7 scanf("%d" , &n); 8 while(n--) 9 {10 scanf("%d" , &next);11 if(next > now)12 ans += (next - now) * 6 + 5;13 else14 ans += (now - next) * 4 + 5;15 now = next;16 }17 printf("%d" , ans);18 }
1008. Elevator (20)(模拟题)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。