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\n",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\n",sum+n*5);
    }
    return 0;
}
//AC

hdu_1008_Elevator_201308191629的更多相关文章

随机推荐

  1. Mobile

    模块===包   传统开发:整个网页我们写了一个js文件,所有的特效都写在里面了. 缺点:耦合度太高,代码关联性太强,不便于后期维护,会造成全局污染. 发生的请求次数过多,依赖模糊,难于维护. 以上都 ...

  2. [ BZOJ 2134 ] 单选错位

    \(\\\) \(Description\) 一共\(N​\)道题目,第\(i​\)道题有\(A_i​\)个选项,现在有一个人做完了所有题目,但将每一道题的答案都写到了下一道题的位置\((​\)第\( ...

  3. es6杂记

    es6杂记 let 和 const let 仅在代码块里有效 { let a = 10; var b = 1; } a // ReferenceError: a is not defined. b / ...

  4. JavaScript的相关知识

      Oject.assign()   // Cloning an object var obj = { a: 1 }; var copy = Object.assign({}, obj); conso ...

  5. JS——事件冒泡与捕获

    事件冒泡与事件捕获 1.冒泡:addEventListener("click",fn,false)或者addEventListener("click",fn): ...

  6. JS——scroll

    scrollWidth:父div宽度小于子div宽度,父div scrollWidth宽度为子div的宽度,大于则为本身的宽度width+padding scrollHeight:父div高度小于子d ...

  7. java攻城狮之路--复习xml&dom_pull编程

    xml&dom_pull编程: 1.去掉欢迎弹窗界面:在window项的preferences选项中输入“configuration center” 找到这一项然后     把复选框勾去即可. ...

  8. css 众妙之门 学习笔记

    伪类: 结构伪类: :empty :only-child :before :after :active :hover :focus :link :visited :first-child :last- ...

  9. 【译】x86程序员手册10 - 第4章系统架构

    1.1.2 Part II -- Systems Programming 系统编程 This part presents those aspects of the architecture that ...

  10. 【译】x86程序员手册03 - 2.1内存组织和分段

    2.1 Memory Organization and Segmentation 内存组织和分段 The physical memory of an 80386 system is organized ...