1008. Elevator (20)
来源:互联网 发布:java视频教程 编辑:程序博客网 时间:2024/06/06 03:48
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<vector>#include <sstream>#include<cmath>#include<iomanip>#include<iostream>#include <ctype.h>#include <stdlib.h>#include <algorithm>using namespace std;//1008. Elevator (20)int main(){int n;cin >> n;int nums[10000] = { 0 };for (int i = 0; i < n; i++){cin >> nums[i];}int mintues = nums[0] * 6 + 5;//从最底层到第一个数对应的层数for (int i = 1; i < n; i++){int minus = nums[i] - nums[i - 1];//计算差值,通过正负判断电梯是往上还是往下if (minus>0){mintues += minus * 6 + 5;}else{mintues += abs(minus) * 4 + 5;}}cout << mintues;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)
- visual studio中,一个解决方案中含有多个项目,如何才能执行我想运行的项目?
- ./show_file: error while loading shared libraries: libts-0.0.so.0: cannot open shared object file: N
- Python的函数
- msp430学习笔记之时钟
- uploadify大文件上传IO Error问题解决方案
- 1008. Elevator (20)
- aurix中AD采样
- ibatis中的分表
- android post 传参数和图片到服务器
- HTML规范 - 代码格式
- LeetCode40:Combination Sum II
- 黑马程序员——oc中的方法
- HTML规范 - 内容语义
- x264 encode example code