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;
    } 
  • 相关阅读:
    Scala学习笔记(四)—— 数组
    Scala学习笔记(三)—— 方法和函数
    Scala学习笔记(二)——Scala基础
    Scala学习笔记(一)
    HDFS和GFS对比学习
    HDFS原理学习
    c++日历问题
    Mapreduce学习
    c++动态规划解决数塔问题
    C++——数码管
  • 原文地址:https://www.cnblogs.com/love-sherry/p/6745170.html
Copyright © 2011-2022 走看看