1008. Elevator (20)
来源:互联网 发布:临沂软件开发培训 编辑:程序博客网 时间:2024/06/06 05:11
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,i,sum=0;
cin>>n;
int a[n];
for(i=1;i<=n;i++)
cin>>a[i];
a[0]=0;
for(i=1;i<=n;i++)
if(a[i]<a[i-1])
sum+=((a[i-1]-a[i])*4+5);
else
sum+=((a[i]-a[i-1])*6+5);
cout<<sum;
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)
- goahead3.6.4移植总结
- lombok安装与使用简介
- 事件冒泡
- Bootstrap之制作登录表单
- python 实现决策树画图
- 1008. Elevator (20)
- javaWeb 中web.xml详细配置
- Token ,Cookie和Session的区别--学习笔记
- c#中类的学习以及使用方法
- 为什么traceroute显示的路由和route显示的路由信息不一致?
- Android MediaPlayer 常用方法介绍
- 未来 3~5 年内,哪个方向的机器学习人才最紧缺?
- mybatis sql查询条件有时间时查询效率非常慢
- java线程池(三) Executors.newSingleThreadExecutor