zoukankan      html  css  js  c++  java
  • Elevator

    Problem 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

     1 #include <stdio.h> 
     2 
     3 int main(){
     4     int number;
     5     int floor;
     6     int position;
     7     int time;
     8     int temp;
     9     
    10     while(1){
    11         scanf("%d",&number);
    12 
    13         if(number==0)
    14             break;
    15 
    16         position=0;
    17         time=0;
    18         while(number--){
    19             scanf("%d",&floor);
    20 
    21             if(floor==position)  //如果请求的楼层为当前楼层,则不用移动,时间加上电梯停留的时间
    22                 time+=5;
    23 
    24             else if(floor>position){  //电梯要往上升,计算移动时间和等待时间,改变当前楼层
    25                 temp=(floor-position)*6+5;
    26                 time+=temp;
    27                 position=floor;
    28             }
    29 
    30             else{    //电梯要往下降,计算移动时间和等待时间,改变当前楼层
    31                 temp=(position-floor)*4+5;
    32                 time+=temp;
    33                 position=floor;
    34             }
    35         }
    36 
    37         printf("%d
    ",time);
    38     }
    39         
    40     return 0;
    41 }
  • 相关阅读:
    多项式的一些操作
    AtCoder Grand Contest 036E
    THUWC2017 随机二分图
    THUWC2017 在美妙的数学王国中畅游
    SDOI2017 切树游戏
    ZJOI2017 树状数组
    HNOI2015 接水果
    LOJ6503 Magic
    Charles 抓去app接口的使用
    mysql 字符串类型和数字对比的坑
  • 原文地址:https://www.cnblogs.com/zqxLonely/p/4054517.html
Copyright © 2011-2022 走看看