zoukankan      html  css  js  c++  java
  • 1008 Elevator (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

    Submit:

    #include <iostream>
    using namespace std;
    //目标:求从0层开始,经过 n 个阶段后 电梯总共运行时间
    int main() {
        int n,i,floor,temp,sum=0;
        int up = 6,down = 4,stop = 5;//电梯各阶段所需时间
        scanf("%d",&n);
        for (i=0; i<n ;i++) {
            scanf("%d",&floor);//2 3 1
            if (i==0) sum += floor*up + stop;//17
            else if(temp < floor) sum += (floor-temp)*up+stop;//
            else sum += (temp-floor)*down + stop;
            temp = floor;//2 3
        }
        printf("%d",sum);
        return 0;
    }

    参考:

    柳婼-https://blog.csdn.net/liuchuo/article/details/54561626

    昵称五个字-https://blog.csdn.net/a617976080/article/details/89676670

  • 相关阅读:
    jquery的data、attr、expando
    Vue-router导航问题
    函数声明与函数表达式
    Object.defineProperty方法
    移动端Web开发,ios下 input为圆角
    parseInt和map方法使用案例分析
    字符串处理常见函数
    ES6之Promise的基本用法
    浮动相关
    知识点拾遗
  • 原文地址:https://www.cnblogs.com/cgy-home/p/15119795.html
Copyright © 2011-2022 走看看