zoukankan      html  css  js  c++  java
  • 1008. Elevator (20)

     

    时间限制
    400 ms
    内存限制
    65536 kB
    代码长度限制
    16000 B
    判题程序
    Standard
    作者
    CHEN, Yue

    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 Specification:

    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.

    Output Specification:

    For each test case, print the total time on a single line.

    Sample Input:
    3 2 3 1
    
    Sample Output:
    41
     #include<stdio.h>
     4 
     5 int main()
     6 {
     7     
     8     int n,i,tem;
     9     while(scanf("%d",&n)!=EOF)
    10     {
    11         int index= 0;
    12         int sum = 0;
    13         for(i= 0;i<n;i++)
    14         {
    15             scanf("%d",&tem);
    16             int dis = tem - index;
    17             if(dis > 0)
    18             {
    19                 sum += dis * 6;
    20             }
    21             else
    22             {
    23                 sum -= dis * 4;
    24             }
    25 
    26             sum += 5;
    27             index = tem ;
    28         }
    29 
    30         printf("%d
    ",sum);
    31     }
    32     return 0;
    33 }
  • 相关阅读:
    pyinstaller
    screen
    docker
    rsync
    shutil模块
    mysql innodb 理解
    B 树和B+树存储的区别
    B-树原理分析
    mysql 通过mycat 读写分离
    mysql 主从复制
  • 原文地址:https://www.cnblogs.com/xiaoyesoso/p/4277110.html
Copyright © 2011-2022 走看看