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 }


  • 相关阅读:
    Spring框架构造注入的属性问题type属性
    Spring框架AOP添加日志记录功能
    Spring框架构造注入
    Spring框架AOP原理
    Spring框架构造注入的顺序问题index属性
    Spring框架使用P命名空间进行注入
    工作中的SQL脚本
    spring框架ioc设置注入小demo
    [笔试] C和C++动态内存分配和释放的区别
    [算法] 当今世界最为经典的十大算法投票进行时
  • 原文地址:https://www.cnblogs.com/kking/p/2331820.html
Copyright © 2011-2022 走看看