zoukankan      html  css  js  c++  java
  • Elevator

    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.

    Input
    There are multiple test cases. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100. A test case with N = 0 denotes the end of input. This test case is not to be processed.

    Output
    Print the total time on a single line for each test case.

    Sample Input
    1 2
    3 2 3 1
    0

    Sample Output
    17
    41

    题目意思:上楼每层需要6秒,下楼每层需要4秒,在到达的楼层还要停留5秒

     1 #include<stdio.h>
     2 int main()
     3 {
     4     int n,i,count,f[100];
     5     while(scanf("%d",&n)!=EOF)
     6     {
     7         if(n==0)
     8             break;
     9         count=0;
    10         f[0]=0;
    11         for(i=1; i<=n; i++)
    12         {
    13             scanf("%d",&f[i]);
    14             if(f[i]>f[i-1])
    15                 count=count+(f[i]-f[i-1])*6+5;
    16             else
    17                 count=count+(f[i-1]-f[i])*4+5;
    18         }
    19         printf("%d
    ",count);
    20     }
    21     return 0;
    22 }

    明明是一道水题,可我还是看错意思了,以为在每一层都要停留,该死!

  • 相关阅读:
    【javaSE】Exception in thread "main" java.lang.ArrayStoreException: java.lang.Integer
    property
    多继承与super
    GIL全局解释器锁
    深浅拷贝
    生成器
    迭代器
    设置ll命令
    修改Centos中的ll命令(以 K 为单位显示文件大小)
    打包解压缩命令
  • 原文地址:https://www.cnblogs.com/wkfvawl/p/8734449.html
Copyright © 2011-2022 走看看