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

    题目链接:

    http://acm.hdu.edu.cn/showproblem.php?pid=1008

    题目:

    Elevator

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


    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
     

    题意概括:

    有一个电梯,上一层需要6s,在当前楼层停留需要5s,下一层需要4s,现在电梯要从第0层出发,问按顺序送完一些人到达相应的楼层需要的时间(不需要返回0层)。

    输入:输入一个数n,按顺序输入这N个人要到的楼层

    解题思路:

    纯模拟过程,遇到比上一层大的往上走,遇见小的往下走,每停一次需要5s。

    AC代码:

    # include <stdio.h>
    
    int main ()
    {
        int n,i,sum,sta,a[200];
        while(scanf("%d",&n)!=EOF)
        {
            if(n==0)
                break;
            sum=0; sta=0;
            for(i=0;i<n;i++)
                scanf("%d",&a[i]);
            sum=a[0]*6+5; sta=a[0];
            for(i=1;i<n;i++)
            {
                if(a[i]>a[i-1])
                    sum+=(a[i]-sta)*6+5;
                else if(a[i]<a[i-1])
                    sum+=(sta-a[i])*4+5;
                else
                    sum+=5;
                sta=a[i];
            }
            printf("%d
    ",sum);
        }
        return 0;
    } 
  • 相关阅读:
    IIS部署.net core 的程序后,如何查看控制台的日志?
    Java中string的编码的详细说明
    explicit禁止被用来执行隐式类型转换。仍可以进行显示转换
    判断一个IP字符串为有效的IP方法
    链接原理
    tcp套接字地址
    c/c++中的__attribute__((weak))使用
    关于multiple definition of 错误说明很详细的文章【转载】
    c/c++中结构体中的位域在大小端设备上的内存存储方式----------位域
    TCP之数据缓冲区大小及其限制
  • 原文地址:https://www.cnblogs.com/love-sherry/p/6745170.html
Copyright © 2011-2022 走看看