zoukankan      html  css  js  c++  java
  • PAT-1008 Elevator 解答(with Python)

    1.Description:

    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.

     Notes:

    • 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.
    • For each test case, print the total time on a single line.

    2.Example:

    Input:
    3 2 3 1
    Output:
    41

    3.solutions:

    python version:

     1 """
     2     created by sheepcore on 2020-03-01
     3 """
     4 if __name__ == "__main__":
     5     inputs = input().split()
     6     i = 0
     7     curFloor = 0
     8     upTime = 6
     9     downTime = 4
    10     stopTime = 5
    11     time = 0
    12     while i < eval(inputs[0]):
    13         if eval(inputs[i+1]) > curFloor:
    14             time += (eval(inputs[i + 1]) - curFloor) * upTime + stopTime
    15         else:
    16             time += (curFloor - eval(inputs[i + 1])) * downTime + stopTime
    17         curFloor = eval(inputs[i + 1])
    18         i += 1
    19     print(time, end="")
  • 相关阅读:
    Button 的CommandName 用法
    如何循序渐进向DotNet架构师发展
    用sqlserver进行分布式查询(链接服务器)(转)
    关于.resx
    OO设计原则总结
    为ASP.NET 2.0网站生成唯一程序集
    依赖倒置、控制反转和依赖注入辨析(转)
    通过http地址获取页面内容
    Sql同表去除重复
    动态启动WCF服务
  • 原文地址:https://www.cnblogs.com/sheepcore/p/12391523.html
Copyright © 2011-2022 走看看