zoukankan      html  css  js  c++  java
  • 1008 Elevator (20)(20 分)

    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


    在一座高楼上只有一个电梯,然后有 n 个电梯将要停止的楼层 电梯上升一层 用时 6 秒 , 下降一层用时 4 秒, 在每层停止时 停下5秒
    初始位置为 0 层, 当电梯停止在最后一个位置后不再返回 0 层
    问 电梯需要多长时间完成 n 个任务请求

    #include <iostream>
    #include <algorithm>
    
    using namespace std; 
    
    #define maxn 200
    
    int n , floors[maxn] ; 
    
    int main(){
    
        while(cin >> n ){
            for(int i=1 ; i<=n ; i++){
                cin >> floors[i] ; 
            }
            int sum = 0 ; 
            floors[0] = 0 ; // 第 0 层
    
            for(int i=1 ; i<=n ; i++){
                if(floors[i] - floors[i-1] >= 0 ){ // 上升
                    sum += (floors[i] - floors[i-1]) * 6 ; 
                }else { // 下降
                    sum += abs(floors[i] - floors[i-1]) * 4 ; 
                }
            }
            sum += n * 5 ; // 每层楼停止时 停下 5 秒
            
            cout << sum << endl ;
        }
        return 0 ; 
    }


  • 相关阅读:
    centos 7.0 yum 分开安装 LAMP 环境 +zabbix3.4环境
    互联网产品接入支付功能如何测试?
    python实现:将文本文件分割成多个小文本文件(php也可实现)
    『危机领导力』告诉我们如何带好团队
    Fiddler显示服务器IP的方法
    Google PageSpeed Tools 性能测试分析
    写给浮躁的测试工程师一封信
    数据库事务和锁
    测试工作中ADB命令实战
    git使用基础
  • 原文地址:https://www.cnblogs.com/yi-ye-zhi-qiu/p/9509024.html
Copyright © 2011-2022 走看看