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. spring基础学习---简单配置文件

  2. 什么是JavaScript对象?

    对象是JavaScript的基本数据类型.对象是一种复合值:它将很多值(原始值或者其他对象)聚合在一起,可通过名字访问这些值.对象也可看做是属性的无序集合,每个属性都是一个名/值对.属性名是字符串,因 ...

  3. Effective C++ 深入理解inline

    Effective C++ 深入理解inline inline语义 inline本义是将所调用函数用自身的函数本体替换之,免受函数调用所招致的额外开销,比宏还要不易出错:但是实际上inline的受编译 ...

  4. Codeforces 766E

    题意:给一棵树(1e5),每个节点上有对应权值(0<=ai<=1e6)定义树上两个节点间的距离为路径中节点的异或,求所有节点对间的距离和(包括节点自身也作为节点对,距离为节点权值). 解题 ...

  5. NOIP真题汇总

    想想在NOIP前总得做做真题吧,于是长达一个月的刷题开始了 涉及2008-2016年大部分题目 NOIP [2008] 4/4 1.传纸条:清真的三维DP 2.笨小猴:字符串模拟 3.火柴棒等式:打表 ...

  6. MyBatis分页组件--PageHelper

    一.介绍 PageHelper是国内非常优秀的一款开源的 mybatis 分页插件,它支持基本主流与常用的数据库,例如 Oracle.Mysql.MariaDB.SQLite.Hsqldb 等. 官网 ...

  7. HTTP05--HTML常用知识

    一.URL地址含义 需要搞清URL和URI的差别,以及QueryString的含义. 二.GET和POST的区别 详细介绍可参考文章:http://zengrong.net/post/1802.htm ...

  8. 关于类似vue-cli 脚手架

    #!/usr/bin/env node const download = require('download-git-repo') const program = require('commander ...

  9. JS高级——Function原型链

    基本概念 1.函数可以通过Function new出来,那么Function可以被称作构造函数,被new出来的函数可以被称为一个对象 2.Function既然是构造函数,那么肯定也有原型,它的原型是一 ...

  10. flask web开发日记

    from flask import Flask,make_response,redirect,abort app = Flask(__name__) @app.route('/index1') def ...