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. Android webkit keyevent 事件传递过程

    前言:基于android webview 上定制自己使用的可移植浏览器apk,遇到好多按键处理的问题.所以索性研究了一下keyevent 事件的传递流程. frameworks 层 keyevent ...

  2. PCB 规则引擎之编辑器(语法着色,错误提示,代码格式化)

    对于一个规则引擎中的脚本代码编辑器是非常关键的,因为UI控件直接使用对象是规则维护者,关系到用户体验,在选用脚本编辑器的功能时除了满足代码的编辑的基本编辑要求外,功能还需要包含;语法着色,错误提示,代 ...

  3. 一个thinkphhp的聊天类,感觉还可以

    <?phpnamespace Common\Controller;use Think\Controller;class HxController extends Controller{ /** ...

  4. 【转】linux之type命令

    转自: http://codingstandards.iteye.com/blog/831504 用途说明 type命令用来显示指定命令的类型.一个命令的类型可以是如下之一 alias 别名 keyw ...

  5. cloudera-scm-server启动时出现Caused by: java.io.FileNotFoundException: /var/lib/cloudera-scm-server/.keystore (No such file or directory)问题解决方法(图文详解)

    不多说,直接上干货! 问题详情 查看/var/log/cloudera-scm-server.log的启动日志 问题来源 我在用cloudermanager安装好之后,然后,在对如下. 配置kerbe ...

  6. SVN系列学习(二)-小乌龟的安装与配置

    1.TortoiseSVN的介绍 TortoiseSVN是Subversion版本控制系统的一个免费开源客户端,可以超越时间的管理文件和目录. 2.TortoiseSVN的安装 下载地址:http:/ ...

  7. ios的认识

    刚进了ios兴趣班,第一次使用苹果电脑,因为苹果电脑和windows电脑使用的区别很大.所以老师教我们苹果电脑的基本使用,以及关于苹果产品的一些认识.我听得热血沸腾,对苹果开发越来越感兴趣,相信下次上 ...

  8. CSS——样式初始化

    腾讯: body,ol,ul,h1,h2,h3,h4,h5,h6,p,th,td,dl,dd,form,fieldset,legend,input,textarea,select{margin:0;p ...

  9. Android Studio 快捷键整理

    Alt+回车 导入包,自动修正 Ctrl+N   查找类Ctrl+Shift+N 查找文件Ctrl+Alt+L  格式化代码Ctrl+Alt+O 优化导入的类和包Alt+Insert 生成代码(如ge ...

  10. 1.CentOS安装Redis

    首要条件:安装VMware,在虚拟机中安装CentOS. 第一次接触CentOS的开发者最好是在虚拟机手动一步步进行安装,并且系统环境选择开发环境,这样可以避免后期自己要安装诸多运行库. 安装步骤: ...