https://pintia.cn/problem-sets/994805342720868352/problems/994805511923286016

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

代码:
#include <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + 10;
int flo[111]; int cmp(int a, int b) {
if(b > a)
return 6 * (b - a);
else if(b < a)
return 4 * (a - b);
else return 0;
} int main() {
int n;
scanf("%d", &n);
for(int i = 1; i <= n; i ++)
scanf("%d", &flo[i]); int time = 0, wait = 0;
wait = n * 5;
for(int i = 1; i < n; i ++) {
time += cmp(flo[i], flo[i + 1]);
}
time = time + wait + flo[1] * 6; printf("%d\n", time); return 0;
}

  

PAT 甲级 1008 Elevator的更多相关文章

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

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

  2. PAT 甲级 1008 Elevator (20)(20 分)模拟水题

    题目翻译: 1008.电梯 在我们的城市里,最高的建筑物里只有一部电梯.有一份由N个正数组成的请求列表.这些数表示电梯将会以规定的顺序在哪些楼层停下.电梯升高一层需要6秒,下降一层需要4秒.每次停下电 ...

  3. PAT甲级——1008 Elevator

    PATA1008 Elevator The highest building in our city has only one elevator. A request list is made up ...

  4. 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 ...

  5. PAT Advanced 1008 Elevator (20 分)

    The highest building in our city has only one elevator. A request list is made up with N positive nu ...

  6. PAT甲级——A1008 Elevator

    The highest building in our city has only one elevator. A request list is made up with N positive nu ...

  7. PAT Advanced 1008 Elevator (20) [数学问题-简单数学]

    题目 The highest building in our city has only one elevator. A request list is made up with N positive ...

  8. PAT甲级1008水题飘过

    题目分析:上去下来到达的时间和数量 #include<iostream> using namespace std; ]; int main(){ int n; while(scanf(&q ...

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

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

随机推荐

  1. scRNA-seq genomic analysis pipline

    a scRNA-seq genomic anlysis pipline .caret,.dropup>.btn>.caret{border-top-color:#000!important ...

  2. 20155337 2016-2017-2 《Java程序设计》第一周学习总结

    20155337 2016-2017-2 <Java程序设计>第一周学习总结 教材学习内容总结 我们主要学习的是JAVA SE平台也就是标准平台-Java SE四个组成部分:JVM .JR ...

  3. installshield 判断mdmcpq.inf和usbser.sys 是否 存在

    1.产品上位机程序,需要驱动支持,在安装  exe程序的时候,连同NET框架4.0和 .inf驱动文件,一起安装, 安装驱动的时候,会发现, 如果系统 C:\Windows\Inf 缺少mdmcpq. ...

  4. day 1 异常基本功能

    1.什么是异常?程序出现的错误 In [1]: open('xxx.txt') ------------------------------------------------------------ ...

  5. Session丢失——解决方案

    先抄下别人的作业(原帖:http://www.cnblogs.com/zhc088/archive/2011/07/24/2115497.html) Session丢失已经是一种习以为常的问题了,在自 ...

  6. Vue视图

    1. 基本模板语法 1.1 插值 文本 数据绑定最常见的形式就是使用“Mustache”语法 (双大括号) 的文本插值 v-text 指令也可以用于数据绑定,如果要更新部分的 textContent ...

  7. 【MYSQL经验】MYSQL经验总结

    1.决定是否添加一个新的所以并部署它需要考虑很多因素

  8. 用原生JS实现一个轮播(包含全部代码和详细思路)

    在我看来要想实现轮播主要是要知道当前位于的页面和即将位于的页面.这个案例是通过改变图片的透明度来实现轮播的效果. 我把涉及的知识点分为两个方面,分别是HTML+css和JS. 第一部分(html+cs ...

  9. MySQL☞视图

    emmm,我本来最先也没注意到视图,然后再某个群里突然说起了视图,吓得本菜鸟赶紧连牛的不敢吹了,只好去科普一下,才好继续去吹牛. 什么是视图: 视图是一张虚拟的表,从视图中查看一张或多张表中的数据. ...

  10. Linux 安装ActiveMQ(使用Mac远程访问)

    阅读本文需要安装JDK 一 ActiveMQ简介 activemq是用java语言编写的一款开源消息总线 activemq是apache出品 activemq消息的传递有两种类型 一种是点对点: 即一 ...