1008. Elevator (20)
来源:互联网 发布:mac如何更新flash 编辑:程序博客网 时间:2024/06/03 17:05
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
#include <iostream>using namespace std;int main(){ int n,m1,m2; cin>>n; int tmp = n; m1 = 0; int sum = 0; while(n--) { cin>>m2; if(m2 > m1) { sum += (m2 - m1)*6; } else { sum += (m1 - m2)*4; } m1 = m2; } sum +=tmp*5; cout<<sum;}
- 1008. Elevator (20)
- 1008. Elevator (20)-PAT
- 【PAT】1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- PAT 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- PAT 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- 解决eclipse add and remove 项目名带括号
- multipart/form-data请求与文件上传的细节
- 9.14 学到了什么
- Java HashSet 比较器
- Python学习系列----第四章 函数
- 1008. Elevator (20)
- 树的三种后序遍历
- Color & Font
- Java回调机制解读
- Hibernate入门到开发(一)之入门小程序
- CNETOS LINUX 计划任务详解
- Linux下的压缩之tar,zip,gzip,bzip2
- (Leetcode)400. Nth Digit
- springmvc 学习1 springmvc的入口