zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    谷歌浏览器network请求时间(stalled,DNS Lookup,Waiting)分析以及解决方案
    Maven项目下启动后Eclipse报错:org.springframework.web.context.ContextLoaderListener
    探讨ES6的import export default 和CommonJS的require module.exports
    Node.js+websocket+mongodb实现即时聊天室
    slider轮播插件的多种写法
    原生canvas写的飞机游戏
    vue父组件如何向子组件中传递数据?
    vue计算属性VS侦听属性
    vue等单页面应用优缺点
    vue自定义过滤器的创建与使用
  • 原文地址:https://www.cnblogs.com/xl1027515989/p/3268271.html
Copyright © 2011-2022 走看看