zoukankan      html  css  js  c++  java
  • PTA (Advanced Level) 1008 Elevator

    Elevator

      The highest building in our city has only one elevator. A request list is made up with Npositive 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 Npositive 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代表电梯会停留的层数,之后给出n个数,代表电梯具体停留的楼层,电梯初始在0层,每向上一层会消耗6秒,每向下一层会消耗4秒,在需停留层会停留5秒,电梯最后不需要返回0层。

      模拟一下电梯的运行过程即可。

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 int n, t = 0, nowf = 0; //n为电梯需停留层数, t为已经消耗的时间, nowf是电梯当前所在的楼层
     4 int main()
     5 {
     6     scanf("%d", &n);    //输入电梯需停留层数
     7     while(n--){
     8         int floors;
     9         scanf("%d", &floors);   //输入下一个要停留的楼层
    10         while(nowf < floors){   //向上运行
    11             nowf++;
    12             t += 6;
    13         }
    14         while(nowf > floors){   //向下运行
    15             nowf--;
    16             t += 4;
    17         }
    18         t += 5; //停留
    19     }
    20     printf("%d
    ", t);
    21     return 0;
    22 }
  • 相关阅读:
    [转]ORACLE 异常错误处理
    Oracle 返回结果集的 存储过程
    [转]Oracle字符串拼接的方法
    [转]Install App to SD
    [转]重新分配内置存储空间 android手机
    Oracle SQL Developer 操作
    [转].net 调用oracle存储过程返回多个记录集
    [转]使用ADO.NET访问Oracle存储过程
    [转]Oracle ORA-01403: no data found Exception SYS_REFCURSOR
    [转]Oracle开发专题之:%TYPE 和 %ROWTYPE
  • 原文地址:https://www.cnblogs.com/suvvm/p/10672202.html
Copyright © 2011-2022 走看看