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 }
  • 相关阅读:
    怎么对Navicat for Oracle 调试
    老版本的java代码与新代码如何找出差异
    Oracle 外部表是做什么用的
    如何在Navicat 中编辑和记录
    如何使用文件对比工具文件夹比较会话菜单
    哪些工具可以用来进行Bug管理
    5类开发者须知的工具
    怎么找出代码之间的差异
    Beyond Compare不仅可以修改网页代码
    文件对比工具有哪些用途
  • 原文地址:https://www.cnblogs.com/suvvm/p/10672202.html
Copyright © 2011-2022 走看看