1008. Elevator (20)
来源:互联网 发布:市场大数据分析 编辑:程序博客网 时间:2024/06/16 16:38
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<stdio.h>#include<iostream>#include<string>using namespace std;int main(){int n;cin>>n;int order[n];for(int i = 0; i < n; i++){cin>>order[i];}int sum = 0;int level = 0;for(int i = 0; i < n; i++){int dis = order[i] - level;if(dis > 0)sum += 6*dis;if(dis < 0)sum += -1*4*dis;sum += 5;level = order[i];}cout<<sum<<endl;return 0;}
- 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)
- OpenCV2编程手册笔记之 4.2计算图像的直方图
- HDOJ1233. 还是畅通工程(并查集+最小生成树)
- SQL Injection(1)
- Java Collection的操作示例
- 面试OR笔试30——单链表环入口节点
- 1008. Elevator (20)
- leetcode 52. N-Queens II DFS深度优先遍历
- Android学习笔记三十七之基于TCP的socket通信
- Spark 机器学习《一》
- iOS开发中方法延迟执行的几种方式
- HeapCreate第三个参数dwMaximumSize
- 响铃:SaaS决胜的终极战场:解决个性化与边际成本的矛盾
- Python操作MySQL数据库9个实用实例
- MySQL 5.7 (1启动方式)