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

    Elevator

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 52791    Accepted Submission(s): 29174


    Problem Description
    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
    There are multiple test cases. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100. A test case with N = 0 denotes the end of input. This test case is not to be processed.
     
    Output
    Print the total time on a single line for each test case. 
     
    Sample Input
    1 2
    3 2 3 1
    0
     
    Sample Output
    17
    41
     
    Author
    ZHENG, Jianqiang
     
    Source
     
    Recommend
    JGShining   |   We have carefully selected several similar problems for you:  1071 1170 1006 1007 1032 
     
    数学水题,特别简单
     
    题意:在我们城市里,有一个最高的大楼,可是这个大楼只有一个电梯。现在有一个由N个正整数组成请求列表,表示一群人要到达的楼层。而这个电梯要花6秒钟时间上升一层,4秒钟时间下降一层,每层楼的停留时间为5秒钟。对于给出的请求列表,要让那群人达到各自的楼层,总共要花多少时间呢?求出这个时间。假设电梯一开始事在0层,当把人送完后并不需要回到0层。
     
    附上代码:
     1 #include <iostream>
     2 #include <cstdio>
     3 using namespace std;
     4 int main()
     5 {
     6     int n,m,i,j;
     7     while(~scanf("%d",&n)&&n)
     8     {
     9         int sum=0,t=0;
    10         while(n--)
    11         {
    12             scanf("%d",&m);
    13             if(m>t)       //上楼
    14                 sum=sum+(m-t)*6;
    15             else          //下楼
    16                 sum=sum+(t-m)*4;
    17             sum+=5;       //每次停留需要5秒
    18             t=m;
    19         }
    20         printf("%d
    ",sum);
    21     }
    22 }
     
  • 相关阅读:
    关于 OpenSmtp 邮件标题过长后出现乱码问题的解决
    用于解析 sohu 新闻页面的 XSLT 文件
    CEGUI 0.7x实现下划线描边图文混排等效果
    Hash算法说明
    D3DXMatrixShadow 函数
    DLL动态链接库和LIB静态链接库之程序员经验分析
    printf格式控制符的完整格式(转载)
    深入说明HDR技术
    Irrlicht不定期分析
    8.3实例程序:平面阴影
  • 原文地址:https://www.cnblogs.com/pshw/p/4760210.html
Copyright © 2011-2022 走看看