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 }


  • 相关阅读:
    图像处理之优化---任意半径局部直方图类算法在PC中快速实现的框架
    新的验证方式---短信验证和语言验证
    习武 之路---通背拳和苗刀!
    模式识别之Shape Context---利用Shape Context进行形状识别
    ELK 部署
    rsync实现文件备份同步
    oracle-3-子查询和常用函数
    oracle-2中commit 详解
    使用nginx绑定域名,代理gitlab
    Linux Crontab 安装使用详细说明
  • 原文地址:https://www.cnblogs.com/kking/p/2331820.html
Copyright © 2011-2022 走看看