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 }


  • 相关阅读:
    清除富文本样式
    jquery--cookie应用
    Log4j 配置详解
    判断请求是否为ajax
    日期工具类
    Windows Server2012 KB2919355 补丁无法安装
    安装系统步骤:
    大白菜u盘启动盘制作工具取消赞助商方法详解
    视频使用教程
    检查网络是否正常的几种命令
  • 原文地址:https://www.cnblogs.com/kking/p/2331820.html
Copyright © 2011-2022 走看看