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. java基础篇一

    引言 本人系南京一小小学校的大三小小菜鸟,三年来学了很多杂七杂八的,也荒废了大量的时间,马上就要秋招了,之前也看了不少面试题,备选了一些简单的项目,看了不知多少本的几百页厚的各种知识的pdf电子书,发 ...

  2. create-react-app 超级慢的解决方法

    create-react-app超级慢的解决方法 在操作官方实例Create React App时,需要执行指令: create-react-app my-app 来创建一个新的React应用.由于某 ...

  3. Goodbye 2019,Welcome 2020 | 沉淀 2020

    引言 时间如梭,娃都可以打酱油了. 转眼间第一个五年计划,已过了一半. 年终总结是个打脸的好地方,曾经夸下的海口,有的真的成了海口. 所幸,一切都在按好的方向发展.但乐观背后容易忽略潜在的问 ...

  4. CouchDB学习-介绍

    官方文档 CouchDB 1文档存储 CouchDB服务器主机是一个存储文档的数据库.每一个文档在数据库中都有唯一的名字.CouchDB提供RESTful HTTP API用来读取和更新(添加,编辑, ...

  5. NPOI 设置下拉列表

    HSSFWorkbook workbook = new HSSFWorkbook();//创建工作簿 ISheet sheet = workbook.CreateSheet();//创建sheet页 ...

  6. 不看好 git ,也看不懂为什么那么多人去使用 git

    上来就亮明观点,符合我的性格.呵呵呵. 为什么不看好 git 呢? 首先,我们来看看 git 产生的背景. git 是 Linus 开发的,最初的目的,是为了管理 Linux 系统的源代码.这是一个分 ...

  7. linux中批量添加文件前缀的操作

    需要在文件夹内所有txt文件的文件名前面添加"gt_"; 就是由原来的文件“xxx.txt”变成“gt_xxx.txt”: 网上搜来的脚本如下: for i in `ls`; do ...

  8. idea常用快捷键大全

    Idea常用快捷键大全,拿小本本记下来,忘记了可以方便查找. 编写代码 Ctrl+Shift + Enter,语句完成. “!”,否定完成,输入表达式时按 “!”键. Ctrl+E,最近的文件. Ct ...

  9. PlayJava Day029

    1.Java Reflection:Reflection(反射)是被视为动态语言的关键 反射机制允许程序在执行期借助于Reflection API取得任何类的内部信息 并能直接操作任意对象的内部属性及 ...

  10. EF实体类指定部分属性不映射成数据库字段特性

    添加NotMapped 特性 /// <summary> /// 用户名 /// </summary> [NotMapped] public string user_name ...