PAT-A-1008. Elevator (20)
来源:互联网 发布:万国数据在美国上市吗 编辑:程序博客网 时间:2024/06/03 18:38
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>#include<cstdio>using namespace std;int a[110];int main(){ int num; cin >> num; int up = 0, down = 0; a[0] = 0; int ans; for (int i = 1; i <= num; i++) { cin >> a[i]; ans = a[i] - a[i - 1]; if (ans>0) up += ans; else down = down - ans; } int time = up * 6 + down * 4 + num * 5; cout << time << endl; system("pause"); return 0;}
- PAT A 1008. Elevator (20)
- PAT(A) - 1008. Elevator (20)
- PAT A 1008. Elevator (20)
- PAT-A 1008. Elevator (20)
- PAT-A-1008. Elevator (20)
- PAT-A 1008. Elevator (20)
- PAT-A 1008. Elevator
- 1008. Elevator (20)-PAT
- 【PAT】1008. Elevator (20)
- PAT 1008. Elevator (20)
- PAT 1008. Elevator (20)
- PAT 1008. Elevator (20)
- PAT 1008. Elevator (20)
- pat 1008. Elevator (20)
- PAT 1008. Elevator (20)
- PAT 1008. Elevator (20)
- PAT甲 1008. Elevator (20)
- 【PAT甲级】1008. Elevator (20)
- JS学习-初学Ajax
- 秒杀多线程第十一篇 读者写者问题
- 进程与线程
- 开启一个新世界的大门
- 144. Binary Tree Preorder Traversal
- PAT-A-1008. Elevator (20)
- 秒杀多线程第十二篇 多线程同步内功心法——PV操作上
- Qt 添加外部库文件
- SDKD 2017 Spring Team Training A--B
- 爬虫遇到的问题
- 使用D3和FileReader在线生成树形图
- Iptables入门
- 如何彻底解决SpringMVC4.0下使用解决@ResponseBody 中文乱码问题
- mhn在安装时libev-4.15.tar.gz安装出错