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. servlet3.0 JQuary Ajax基本使用

    servlet3.0 没有web.xml文件,需要使用注解进行配置. js: $(document).ready(function(){ $("#btn").click(funct ...

  2. TypeScript `unknown` 类型

    unknown 字面理解和 any 其实没差,任何类型都可赋值给它,但有一点, Anything is assignable to unknown, but unknown isn't assigna ...

  3. 解决Logger在Android Studio 3.1版本无法正常加载tag格式

    已经升级到Android Studio 3.1的同学可能会发现一个问题, Logcat中如果短时间出现多条日志tag相同, 只会显示第一条日志的tag, 后面的tag会自动隐藏, 这时com.orha ...

  4. Python 线程 的 锁

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA9gAAAG7CAYAAAA41T2sAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjw ...

  5. 【洛谷4933】大师(DP)

    题目: 洛谷4933 分析: (自己瞎yy的DP方程竟然1A了,写篇博客庆祝一下) (以及特斯拉电塔是向Red Alert致敬吗233) 这里只讨论公差不小于\(0\)的情况,小于\(0\)的情况进行 ...

  6. ACM_3n+1问题(克拉兹问题+线段树区间查询最大值)

    3n+1问题 Time Limit: 2000/1000ms (Java/Others) Problem Description: 考虑如下的序列生成算法:从整数n开始,如果n是偶数,把它除以2:如果 ...

  7. Android 显示意图和隐式意图的区别

    意图在android的应用开发中是很重要的,明白了意图的作用和使用后,对开发会有很大帮助.如果没有把意图搞懂,以后开发应用会感觉缺些什么.        意图的作用:        1.激活组件   ...

  8. Unicode gbk gb2312 编码问题 [转载]

    原文地址: http://www.cnblogs.com/csn0721/archive/2013/01/24/2875613.html HTML5 UTF-8 中文乱码   <!DOCTYPE ...

  9. SVN系列学习(四)-TortoiseSVN其他操作

    1.新建分支 第一步:从SVN上CheckOut一份,要作为分支模板的文件 第二步:右击[TortoiseSVN]-选择[Branch/tag] 备注说明,[指明分支路径] 第三步:删除电脑上的ZJH ...

  10. [ NOIP 2002 ] TG

    \(\\\) \(\#A\) 均分纸牌 有\(N\)堆纸牌,每堆有若干张,但纸牌总数必为\(N\)的倍数.可以在任一堆上取若干张纸牌,然后移动给其左右任意一侧的纸牌堆,求将所有的牌堆牌数都变为平均值最 ...