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. python学习之网络编程基础

    引入场景:客户与银行关系 银行职员负责给客户提供取钱服务,客户通过账户密码跟银行职员建立合作关系.此时银行职员就可以作为服务器,当用户A取完钱后他需要等待下一个用户的接入,用户的账号密码就是建立合作关 ...

  2. 利用python操作mrjob实例---wordcount

       网上利用java实现mr操作实例相对较多,现将python实现mr操作实例---Wordcount分享如下: 在操作前,需要作如下准备: 1.确保linux系统里安装有python3.5,pyt ...

  3. 用函数指针将字符串 ”hello world“ 输出为 "world hello”

    /************************************************************************* > File Name: 指针数组2.c & ...

  4. QPushButton槽函数触发两次的问题

    以前经常使用qt creator界面管理直接跳转到槽函数没发现这个问题,今天手动写了个槽函数发现按键会触发两次.根据网上的说法是按键会自动连接一个槽函数,如果我们手动添加的槽函数命名规则符合槽函数的命 ...

  5. Springboot启动报Multiple Dockets with the same group name are not supported. The following duplicate groups were discovered.

    解决方法: 属于bean重复,根据错误提示剔除多于的Bean引用!

  6. 20155206 实验一《Java开发环境的熟悉》实验报告

    实验内容 使用JDK编译.运行简单的Java程序 使用IDEA 编辑.编译.运行.调试Java程序. 实验代码 `import java.text.DecimalFormat; import java ...

  7. 20155218 《Java程序设计》实验三(Java面向对象程序设计)实验报告

    20155218 <Java程序设计>实验三(Java面向对象程序设计)实验报告 一.实验内容及步骤 (一)编码标准 在IDEA中使用工具(Code->Reformate Code) ...

  8. 20155332 mybash的实现

    mybash 的实现 码云链接 https://gitee.com/bestiisjava2017/laura5332/blob/master/%E4%BF%A1%E6%81%AF%E5%AE%89% ...

  9. centos7安装cacti

    参考博客地址:https://blog.csdn.net/kenn_lee/article/details/80565385 Cacti是一套基于PHP,MySQL,SNMP及RRDTool开发的网络 ...

  10. 【AHOI2013】差异

    题面 题解 $ \because \sum_{1 \leq i < j \leq n} i + j = \frac{n(n-1)(n+1)}2 $ 所以只需求$\sum lcp(i,j)$即可. ...