1008. Elevator (20)
来源:互联网 发布:人工智能电影图片 编辑:程序博客网 时间:2024/06/16 08:28
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, now,next,total;while(cin>>n){now =next=total=0;while (n--){cin>>next;if (next>now){total +=(next-now)*6+5; }else{total +=(now-next)*4+5;}now =next;}cout<<total<<endl;}return 0;}
sampleout 起初手算,算出来一直不是41.
- 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)
- Svn linux服务端安装及配置
- 喷水装置(一)
- python3.6安装matplotlib、numpy时报错ImportError
- HDU 3667 Transportation (最小费用最大流)
- H
- 1008. Elevator (20)
- VScode编辑器 ~常用快捷键
- 三分法模板
- 嵌入式开发IO基础
- 2017阿里巴巴内推面经—测试开发岗
- Unity3D异步加载
- java访问Hbase
- redis学习及实践3---Jedis、JedisPool、Jedis分布式实例介绍
- Maven坐标和仓库