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 ;
}

PAT 1008 Elevator 数学的更多相关文章

  1. PAT 1008. Elevator (20)

    1008. Elevator (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The highest ...

  2. PAT 1008 Elevator

    1008 Elevator (20 分)   The highest building in our city has only one elevator. A request list is mad ...

  3. pat 1008 Elevator(20 分)

    1008 Elevator(20 分) The highest building in our city has only one elevator. A request list is made u ...

  4. PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642 题目描述: The highest building in our city has ...

  5. PAT 甲级 1008 Elevator (20)(代码)

    1008 Elevator (20)(20 分) The highest building in our city has only one elevator. A request list is m ...

  6. PAT甲 1008. Elevator (20) 2016-09-09 23:00 22人阅读 评论(0) 收藏

    1008. Elevator (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The highest ...

  7. 【PAT甲级】1008 Elevator (20分)

    1008 Elevator 题目: The highest building in our city has only one elevator. A request list is made up ...

  8. PAT 1008

    1008. Elevator (20) The highest building in our city has only one elevator. A request list is made u ...

  9. Problem : 1008 ( Elevator )

    好操蛋啊,电梯竟然能原地不动,你大爷的,这逻辑,太弱智了.... Problem : 1008 ( Elevator )     Judge Status : Accepted RunId : 103 ...

随机推荐

  1. 使用saltstack自动部署K8S

    使用saltstack自动部署K8S 一.环境准备 1.1 规划 1. 操作系统 CentOS-7.x-x86_64. 2. 关闭 iptables 和 SELinux. 3. 所有节点的主机名和 I ...

  2. HttpRunner学习4--使用正则表达式提取数据

    前言 在HttpRunner中,我们可通过extract提取数据,当响应结果为 JSON 结构,可使用 content 结合 . 运算符的方式,如 content.code,用起来十分方便,但如果响应 ...

  3. 在Mac上Python多版本切换

    1.安装Homebrewhttps://brew.sh/index_zh-cn.html 2.通过brew安装pyenv1)命令行输入:$ brew install pyenv(如果一直卡在Updat ...

  4. CentOS 7上的系统管理之:Systemd和systemctl

    参考资料: Chapter 10. Managing Services with systemd Red Hat Enterprise Linux 7 | Red Hat Customer Porta ...

  5. 制作excel下拉菜单

    1.选中excel中需要制作下拉菜单的单元格/列/行,点击‘数据’——'数据验证': 2.允许选择'序列',来源中手动输入需要的内容,以逗号(,)分割:  3.如下图,此列都具有下拉选择的功能:

  6. 数据库性能提升利器—Mycat数据切分

    一.前言      数据库是每个系统都不可缺少的东西,里面记录了系统各种数据资料.但是如今的数据膨胀的时代,数据库性能不能满足我们的需要了.所以我们要对数据库进行强化,就用到了Mycat. 二.何为数 ...

  7. 在Ubuntu 18.04系统上安装Pydio Cells详细图文教程

    前言   基于云的协作工具Pydio cell提供了一系列灵活的特性,包括应用内消息传递.文件共享和版本控制.下面逐步介绍安装过程. Pydio cell最初是一个简单的基于云的文件共享系统,但经过升 ...

  8. 使用Condition

    /** * ReentrantLock使用Condition对象来实现wait和notify的功能* 使用Condition时,引用的Condition对象必须从Lock实例的newCondition ...

  9. Spring Boot 处理异常返回json

    spring boot 老版本处理异常  对于浏览器客户端,返回error数据 对于非浏览器返回json数据, 主要取决于你的请求head 是什么 但是当我们自定义了:  老版本无论请求什么都会返回j ...

  10. Navicat远程连接MySQL8,必知防坑策略

    项目上线是每一个开发工程师面临收获前面抓紧时间开发的成果,但有时我们上线项目首先需要做一些相关的业务测试.通过Xshell远程连接后使用命令行的方式连接操作Mysql这个没什么太大的你问题.但每次通过 ...