zoukankan      html  css  js  c++  java
  • 1008. Elevator

    1008. Elevator (20)

    时间限制
    400 ms
    内存限制
    32000 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
     1 #include <iostream>
    2 #include <fstream>
    3 #include <vector>
    4 #include <string>
    5 #include <algorithm>
    6 #include <map>
    7 #include <stack>
    8 #include <cmath>
    9 #include <queue>
    10 #include <set>
    11
    12
    13 using namespace std;
    14
    15
    16 int main()
    17 {
    18
    19
    20
    21
    22 int num_level;
    23
    24 while( cin >> num_level )
    25 {
    26
    27 int current = 0;
    28 int target = 0;
    29 int time = 0;
    30
    31 for( int i = 0 ; i< num_level ; ++i )
    32 {
    33 cin >> target;
    34
    35 if( target != current )
    36 {
    37 if(target > current )
    38 {
    39 time += ( target - current )*6 + 5;
    40 }
    41 else
    42 {
    43 time += ( current - target )*4 + 5;
    44 }
    45
    46 }
    47 else
    48 {
    49 time += 5;
    50 }
    51
    52 current = target;
    53
    54 }
    55
    56 cout << time << endl;
    57 }
    58
    59
    60
    61
    62
    63
    64
    65
    66 return 0;
    67 }


  • 相关阅读:
    初识函数
    文件操作
    set集合,深浅拷⻉以及部分知识点补充
    is和==的区别以及编码、解码
    python数据类型三(字典)
    python数据类型二(列表和元组)
    python数据类型一(重点是字符串的各种操作)
    python基础二
    python基础一
    【1】 肿瘤医学研究前言进展
  • 原文地址:https://www.cnblogs.com/kking/p/2331820.html
Copyright © 2011-2022 走看看