• hdu_1008_Elevator_201308191629


    Elevator
    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 34480    Accepted Submission(s): 18803


    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


    //hdu-1008-Elevator
    #include <stdio.h>
    #include <stdlib.h>

    int max[110],min[110];

    int main()
    {
        int n;
        while(scanf("%d",&n),n)
        {
            int i,j,k,m,sum=0;
            int *a;
            j=k=0;
            a=(int *)malloc(n*sizeof(int));
            memset(max,0,sizeof(max));
            memset(min,0,sizeof(min));
            scanf("%d",&a[0]);
            max[a[0]]++;
            for(i=1;i<n;i++)
            {
                scanf("%d",&a[i]);
                if(a[i]>a[i-1])
                max[a[i]]++;
                else
                min[a[i]]++;
            }
            for(i=100;i>=0;i--)
            if(max[i]>0)
            {
                j=i;
                break;
            }
            for(i=0;i<=100;i++)
            if(min[i]>0)
            {
                k=i;
                break;
            }
            if(k==0)
            k=j;
            sum=j*6+(j-k)*4+n*5;
            printf("%d ",sum);
            free(a);
        }
        return 0;
    }
    //理解错误,WA


    //hdu-1008-Elevator-2
    #include <stdio.h>

    int main()
    {
        int n;
        while(scanf("%d",&n),n)
        {
            int i,j,k,m,t=0,sum=0;       
            for(i=1;i<=n;i++)
            {
                scanf("%d",&m);
                if(m-t>0)
                {sum+=(m-t)*6;t=m;}
                else
                {sum+=(t-m)*4;t=m;}
            }
            printf("%d ",sum+n*5);
        }
        return 0;
    }
    //AC

  • 相关阅读:
    快速模幂
    UPC-2249 曲线分割【递推】
    maven 服务器
    maven repo
    php-fpm sock
    mysql
    go 1
    xdebug
    centos
    win10 2503 2502
  • 原文地址:https://www.cnblogs.com/xl1027515989/p/3268271.html
Copyright © 2020-2023  润新知