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. 使用adb进行关机(转载)

    转自:http://hi.baidu.com/fangqianshu/item/dc52b92d31b2dd1542634a3d 其实进入adb shell,然后执行reboot -p或者直接在命令行 ...

  2. E20170619-hm

    bucket   n. 水桶; open hash  [词典] [计] 开放散列,开混列; spirit   n. 精神,心灵; 情绪; 勇气; 精髓; flesh   n. 肉; 肉体; 果肉; 皮 ...

  3. bzoj2730矿场搭建(Tarjan割点)

    2730: [HNOI2012]矿场搭建 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1771  Solved: 835[Submit][Statu ...

  4. [Swift通天遁地]三、手势与图表-(11)制作雷达图表更加形象表示各个维度的情况

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  5. HttpClient Get请求实例

    Httpclient是我们平时中用的比较多的,但是一般用的时候都是去网上百度一下,把demo直接拿过来改一下用就行了,接下来我们来看他的一些具体的用法.Apache HttpComponents™项目 ...

  6. JavaScript判断对象数组中是否存在某个对象【转】

    1. 如果要判断数组中是否存在某个元素的话很好判断,直接用数组的indexOf方法就好,存在返回当前索引不存在返回-1 var arr=[1,2,3,4] arr.indexOf(3) arr.ind ...

  7. hdu2029

    http://acm.hdu.edu.cn/showproblem.php?pid=2029 #include<stdio.h> #include<string.h> #inc ...

  8. ACM_Repeating Characters

    Repeating Characters Time Limit: 2000/1000ms (Java/Others) Problem Description: For this problem, yo ...

  9. C#入门经典 Chapter3 变量和表达式

    3.1 C#基本语法 分号结束语句 花括号字符不需要附带分号 缩进     注释:/*....*/,//,/// 区分大小写 3.2 C#控制台应用程序的基本结构 namespace Chapter3 ...

  10. html5——拖拽

    基本情况 在HTML5的规范中,我们可以通过为元素增加draggable="true"来设置此元素是否可以进行拖拽操作,其中图片.链接默认是开启的. 拖拽元素 页面中设置了drag ...