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 1

Sample Output:

41

题目意思:电梯从0层开始向上运行,依次给出电梯所到达的楼层数,电梯上升一层需要6s,电梯下降一层需要4s,电梯停下来需要5s,问走完所有电梯要到达的楼层总共花了多少时间。

解题思路:确定电梯当前是向上还是向下,若是a[i]>a[i-1],向上运行,需要(a[i]-a[i-1])*6秒;若是a[i]<a[i-1],向下运行,需要(a[i]-a[i-1])*4秒。同时每停止一次需要5秒,最后累加起来即可。

#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
using namespace std;
int main()
{
int i,n,sum=;
int a[];
cin>>n;
a[]=;
for(i=;i<=n;i++)
{
cin>>a[i];
}
for(i=;i<=n;i++)
{
if(a[i]>=a[i-])
{
sum+=(a[i]-a[i-])*;
}
else
{
sum+=(a[i-]-a[i])*;
}
}
sum+=n*;
cout<<sum;
return ;
}

最新文章

  1. javascript中的操作符详解1
  2. vs2013 git 使用总结
  3. Zabbix监控Tengine
  4. DevExpress 2015.2发布 看看有哪些更新
  5. BZOJ3084 : [Algorithmic Engagements 2011]The Shortest Period
  6. CentOS 命令模式下设置静态IP
  7. 前端模块化:RequireJS
  8. uEditor独立图片上传
  9. [Locked] Meeting Room I &amp;&amp; II
  10. express respond.send 和 end的区别
  11. Java异常处理-----程序中的异常处理.启蒙
  12. 关掉那些windows上因权限无法关闭的服务
  13. TEAMWORK1
  14. adb.exe已停止工作
  15. 记CTC原理
  16. CssClass=&quot;Hidden&quot;和Visible=&quot;False&quot;
  17. 关于jsp基本语法:第一章节
  18. Easyui datagrid绑定数据,新增,修改,删除方法(一)
  19. JavaScript 之 最佳位置选择
  20. BZOJ 4517--[Sdoi2016]排列计数(乘法逆元)

热门文章

  1. 【ES6】数组的扩展——扩展运算符
  2. CCPC Wannafly Winter Camp Div2 部分题解
  3. diff命令的妙用
  4. 开源日志框架Exceptionless使用教程
  5. Java连载63-异常处理try...catch...、方法getMessageyu printStackTrace
  6. 3种骚操作,教你查看 Java 字节码!
  7. 1、手写Unity容器--极致简陋版Unity容器
  8. SpringCloud微服务的Eureka
  9. mysql-两种方式安装
  10. 精通awk系列(6):awk命令结构和awk语法结构