problem

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

tip

求电梯载上所有人时,所花时间。

answer

#include<bits/stdc++.h>
using namespace std; #define INF 0x3f3f3f3f int n; int main(){
// freopen("test.txt", "r", stdin);
cin>>n;
int last = 0, now = 0, time = 0;
for(int i = 0; i < n; i++){
cin>>now;
int del = now - last;
if(del == 0) time += 5;
else if(del > 0){
time += del * 6 + 5;
}
else {
del = abs(del);
time += del * 4 + 5;
}
last = now;
}
cout<<time;
return 0;
}

experience

  • 边界条件 del == 0时,还要等5秒

1008 Elevator (20)(20 point(s))的更多相关文章

  1. PAT 甲级 1011 World Cup Betting (20)(20 分)

    1011 World Cup Betting (20)(20 分)提问 With the 2010 FIFA World Cup running, football fans the world ov ...

  2. PAT 甲级 1001 A+B Format (20)(20 分)

    1001 A+B Format (20)(20 分) Calculate a + b and output the sum in standard format -- that is, the dig ...

  3. PAT 1049 数列的片段和(20)(代码+思路分析)

    1049 数列的片段和(20)(20 分) 给定一个正数数列,我们可以从中截取任意的连续的几个数,称为片段.例如,给定数列{0.1, 0.2, 0.3, 0.4},我们有(0.1) (0.1, 0.2 ...

  4. PAT 1033 旧键盘打字(20)(20 分)

    1033 旧键盘打字(20)(20 分) 旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现.现在给出应该输入的一段文字.以及坏掉的那些键,打出的结果文字会是怎样? 输入格式: 输入在2 ...

  5. 【PAT】1019 数字黑洞 (20)(20 分)

    1019 数字黑洞 (20)(20 分) 给定任一个各位数字不完全相同的4位正整数,如果我们先把4个数字按非递增排序,再按非递减排序,然后用第1个数字减第2个数字,将得到一个新的数字.一直重复这样做, ...

  6. PAT 1054 求平均值 (20)(代码+思路+测试用例)

    1054 求平均值 (20)(20 分) 本题的基本要求非常简单:给定N个实数,计算它们的平均值.但复杂的是有些输入数据可能是非法的.一个"合法"的输入是[-1000,1000]区 ...

  7. 【PAT】1018 锤子剪刀布 (20)(20 分)

    1018 锤子剪刀布 (20)(20 分) 大家应该都会玩“锤子剪刀布”的游戏:两人同时给出手势,胜负规则如图所示: 现给出两人的交锋记录,请统计双方的胜.平.负次数,并且给出双方分别出什么手势的胜算 ...

  8. PAT 甲级 1011 World Cup Betting (20)(20 分)(水题,不用特别在乎精度)

    1011 World Cup Betting (20)(20 分) With the 2010 FIFA World Cup running, football fans the world over ...

  9. PTA 1005 Spell It Right (20)(20 分)水题

    1005 Spell It Right (20)(20 分) Given a non-negative integer N, your task is to compute the sum of al ...

  10. A1035 Password (20)(20 分)

    A1035 Password (20)(20 分) To prepare for PAT, the judge sometimes has to generate random passwords f ...

随机推荐

  1. func_get_args()获取参数

    php中func_get_args()可以获取多个参数,讲多个参数放在数组里面. <?php function show() { $attr = func_get_args();//获取输入的参 ...

  2. 【转】WPF绑定模式

    源地址:http://www.cnblogs.com/zjz008/archive/2010/05/26/1744802.html http://blog.csdn.net/haylhf/articl ...

  3. Java容器List接口

    List接口是Java中经常用到的接口,如果对具体的List实现类的特性不了解的话,可能会导致程序性能的下降,下面从原理上简单的介绍List的具体实现: 可以看到,List继承了Collection接 ...

  4. 15、BigDecimal类简介

    BigDecimal类概述 由于在运算的时候,float类型和double很容易丢失精度,在金融.银行等对数值精度要求非常高的领域里面,就不能使用float或double了,为了能精确的表示.计算浮点 ...

  5. win7.wifi热点

    使用本地连接上网,将网卡设为wifi热点 cmd 管理员身份运行 netsh wlan set hostednetwork mode=allow ssid=4Gtest key=12345678 网络 ...

  6. Go语言fmt库的print函数源码解析

    // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a B ...

  7. transparent 透明效果

    background-color:transparent;就是把背景色设置为透明. 实际上background默认的颜色就是透明的属性.所以写和不写都是一样的 span{ width: 0; heig ...

  8. TCP确认延时和Nagle算法

    TCP确认延时和Nagle算法 nagle 算法是   发送端 收到前一个报文的确认然后再发送下一个tcp数据.这样可以避免大量的小数据. TCP_NODELAY选项控制. Delay ACK是   ...

  9. 20155303 2016-2017-2 《Java程序设计》第八周学习总结

    20155303 2016-2017-2 <Java程序设计>第八周学习总结 目录 学习内容总结(Linux命令) 教材学习中的问题和解决过程 代码调试中的问题和解决过程 代码托管 上周考 ...

  10. Spring4笔记6--Spring与AOP

    Spring与AOP: AOP的引入: 主业务经常需要调用系统级业务(交叉业务),如果在主业务代码中大量的调用系统级业务代码,会使系统级业务与主业务深度耦合在一起,大大影响了主业务逻辑的可读性,降低了 ...