1008 Elevator (20)(20 分)

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

PS:起初还想复杂了,看错以为当电梯不用的时候需要回到1层, 英语差没办法...

#include<iostream>
using namespace std;
int main() {
int n, now = 0, next, time = 0;
cin >> n;
for (int i = 0; i < n ; i++) {
cin >> next;
if (next - now > 0)
time += (next - now) * 6+5;
else
time += (now - next) * 4+5;
now = next;
}
cout << time;
return 0;
}

PAT 甲级 1008 Elevator (20)(代码)的更多相关文章

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

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

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

  3. PAT 甲级 1008 Elevator

    https://pintia.cn/problem-sets/994805342720868352/problems/994805511923286016 The highest building i ...

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

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

  6. PAT甲级——1008 Elevator

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

  7. PAT 1008. Elevator (20)

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

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

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

  9. 1008 Elevator (20分)

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

随机推荐

  1. spring boot 实现RESTFull API

  2. 阿里云oss存储图片

    单线程版-上传网络流 import pymysql import oss2 import requests import logging # 添加日志 logging.basicConfig( lev ...

  3. 学JS的心路历程 -物件与原型(二)

    昨天有提到说Object.setPrototypeOf可以指定一个物件为另一个物件的原型,但有想过到底这个原型,也就是[[Prototype]]最终会到何处吗? 答案是Object.prototype ...

  4. SAP自开发程序

    1.显示/查找SAP所有可执行程序清单,双击事务码执行. *&----------------------------------------------------------------- ...

  5. Python调用sqlAlchemy

    import logging from sqlalchemy import Column, String, create_engine from sqlalchemy.ext.declarative ...

  6. spring 中 PO与DTO相互转换的工具类

    public class BeanMapper { /** * 持有Dozer单例, 避免重复创建DozerMapper消耗资源. */ private static DozerBeanMapper ...

  7. 【C++】cout未刷新缓冲区仍会输出的问题

    众所周知,cout是一个流对象,管理一个缓冲区.当使用<<操作符输出字符串时,字符串不是直接被输出到屏幕上,而是首先被插入到该流的缓存(buffer)中.而只有当缓冲区被刷新时,字符串才会 ...

  8. 【Django】ModuleNotFoundError: No module named 'books_ordersschool'

    Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x00000 ...

  9. 判断python字典中key是否存在

  10. Django、Flask、Tornado的比较

    一:常用请求参数的接收 Django中: request.GET/POST Tornado中: self.get_query_argument()/get_query_arguments() self ...