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 }
  • 相关阅读:
    LeeCode 1497. 检查数组对是否可以被 k 整除
    LeetCode 1503. 所有蚂蚁掉下来前的最后一刻
    双指针算法
    最短送餐路程计算, 美团笔试题2020
    最短路算法dijkstra算法
    寻找最小子字符串, 美团笔试题2020
    最大矩形, 统计全1子矩阵
    拼凑硬币, 腾讯
    7月15日
    7月14日
  • 原文地址:https://www.cnblogs.com/xiaoyesoso/p/4277110.html
Copyright © 2011-2022 走看看