HDU1008:Elevator

Elevator

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 42155    Accepted Submission(s): 23093

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

#include<stdio.h>
int main()
{
    int n,i,t,a,b;
    while(scanf("%d",&n)&&n!=0)
    {
        t=0,a=0;
        for(i=0;i<n;i++)
        {
            scanf("%d",&b);
            if(a<=b)
                t+=5+6*(b-a);
            else
                t+=5+4*(a-b);
            a=b;
        }
        printf("%d\n",t);
    }
    return 0;
}

HDU1008:Elevator

时间: 2024-08-29 03:38:43

HDU1008:Elevator的相关文章

ZOJ 3767 Elevator

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5230 题面: Elevator Time Limit: 2 Seconds      Memory Limit: 65536 KB How time flies! The graduation of this year is around the corner. N members of ZJU ACM/ICPC Team decided to hold a par

oo第四次作业

很不幸由于一些原因,前两次的作业我都没有能够提交,虽然都尽力完成了,但没有经过公测和互测的洗礼,也不知道程序写的究竟怎么样,这里我只能简单说一下程序设计的思想了 第一次作业:多项式加减 这次作业中一共写了2个类,第一个类是poly类,用来记录每一个输入的多项式.其中有两个属性coe和index,前者记录系数,后者记录指数. 第二个类是polys,用于把输入拆分为单个的多项式,构造多项式的队列. 第二次作业:傻瓜电梯 按照要求设计了5个类: elevator:电梯类,用于构造一个电梯,并且描述和记

OO前三次作业总结

很庆幸我还活着-- 千言万语尽在一言中-- 好了话不多说直接进入正题,在此对前三次OO作业做一个简单的总结: 第一次作业:第一次接触面向对象-作为一个没有java编程基础的小白来说,面对这个本来比较简单的作业还是比较头疼的,首先不懂java语法,其次不理解面向对象的含义:一脸懵逼-- 好在经过两天的煎熬之后也算是勉强入门了,磕磕碰碰写完了第一次作业,由于初次第一次对于面向对象这个概念没有多少理解并且作业难度也不大,所以整个程序只有一个类,代码量110行:主要难点为输入是否合法的判断以及多项式算法

BUAA_OO 第二单元总结

BUAA_OO 第二单元总结 写在前面 ? 多线程(multi-threading)是指从软件或硬件上实现多个线程并发执行的技术.现代处理器普遍具有多核的特点,支持同一时间执行多个线程,使用多线程技术可以提高程序并发度,整体提高处理性能.因此掌握多线程程序设计技术是CS学习必不可少的一部分. ? 多线程程序设计包括线程协同控制.线程安全保证以及线程程序设计模式等.本文主要总结OO课程第二单元所学的有关多线程程序设计的知识,实践体会,以及技术注记,以备后用. 第五次作业 ? 第五次作业实现了一个单

多线程电梯设计的总结与反思

一.FAFS电梯设计 这是第一次使用java多线程,主要的问题主要集中在两个方面 1.共享资源的数据同步 2.整体架构 先考虑第一个问题: 数据同步的问题显然可以使用synchronized解决,也就是经典的生产者消费者模型. 但是由于初次接触,对锁机制理解不清,我还探索了一种不那么好的方法——volatile,具体使用方法见Whai is volatile 它显然能用在这个问题的解决,但是其实volatile带来的问题很多,比如性能损失,也不具很好的普适性. 第二个问题: FAFS在调度策略的

Oracle 11g数据库详解(2015-02-28更新)

Oracle 11g数据库详解 整理者:高压锅 QQ:280604597 Email:[email protected] 大家有什么不明白的地方,或者想要详细了解的地方可以联系我,我会认真回复的 1   简介 数据库操作主要有以下几步: 1.  启动.停止数据库 2.  连接.断开数据库 3.  创建.修改.删除数据库用户 4.  表空间 5.  新建.修改.删除表 6.  查询.插入.修改.删除表数据 7.  新建.修改.删除视图 8.  新建.修改.删除存储过程 9.  新建.修改.删除触发

解题报告:hdu1008 Elvator

2017-09-07 19:30:22 writer:pprp 比较顺利,最近生活出现了各种问题, 发生了很多矛盾,我要耐下心来,最重要的不是努力不努力,而是选择 希望我能处理好人际关系还有学业上的压力. /* @theme: hdu1008 Elevator @writer:pprp @begin:21:37 @end:19:30 @declare:水题 @data:2017/9/7 */ #include <bits/stdc++.h> using namespace std; int m

HDU1008 Elevator

问题链接:HDU1008 Elevator.基础训练题,用C语言编写程序. 每行的数据有n+1个数据,第一个数据是n,然后是n个数据,即n个要停的层的数据. 电梯开始在0层,上一层需要6秒,下一层需要4秒,停一次需要5秒.电梯最后不需要回到0层. 问题是把所有人都送到各层总共需要多少时间. AC程序如下: /* HDU1008 Elevator */ #include <stdio.h> //#include <stdlib.h> #define MAXN 100 int main

PAT (Advanced Level) Practise:1008. Elevator

[题目链接] 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