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
-------------------------------------------------------------------------------------------------------------------------
#define _CRT_SECURE_NO_WARNINGS

/*总时间=上楼时间*楼层+下楼时间*楼层+停靠时间*/

#include <stdio.h>

int main()
{
int N;
int i;
//开始楼层
int startFloor = 0;
//停靠楼层
int stayFloor;
//上楼时间
int upTime = 6;
//停靠时间
int stayTime = 5;
//下楼时间
int downTime = 4;
//上一站停靠楼层
int lastFloor;
int time; while (scanf("%d", &N) == 1 && N != 0)
{
lastFloor = 0;
time = 0; time += N * stayTime;
while (N)
{
scanf("%d", &stayFloor);
//判断上楼还是下楼
if (stayFloor > lastFloor)
{
time += (stayFloor - lastFloor) * upTime;
}
else
{
time += (lastFloor - stayFloor) * downTime;
}
lastFloor = stayFloor;
N--;
}
printf("%d\n", time);
}
return 0;
}

  

 

ACM1008:Elevator的更多相关文章

  1. PAT1008:Elevator

    1008. Elevator (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The highest ...

  2. OO_BLOG2_多线程电梯模拟

    作业2-1 单部多线程傻瓜调度(FAFS)电梯的模拟 I. 基于度量的程序结构分析 1)程序结构与基本度量统计图 2)分析 ​ 这次作业基本奠定了本人三次电梯作业的基本架构,简述如下: Elevato ...

  3. BUAA面向对象设计与构造——第二单元总结

    BUAA面向对象设计与构造——第二单元总结 第一阶段:单部傻瓜电梯的调度 第二阶段:单部可捎带电梯的调度 (由于我第一次写的作业就是可捎带模式,第二次只是增加了负数楼层,修改了一部分参数,因此一起总结 ...

  4. BUAA-OO-第二单元总结

    OO第二单元总结 一.第五次作业 1.1 设计策略与架构 第五次作业要求的是完成设计支持一架傻瓜电梯的电梯系统.考虑到需要数据结构存放所有的请求,因此构建了FloorRequests类用来存放所有的请 ...

  5. OO第二单元多线程电梯总结分析

    一.概述 这一部分的作业考察的关注点与上一次的作业有所不同,上一次的考察重点主要集中在输入输出的判定以及多态的考察上面,而这一次是让我们进行多线程程序的调度与开发.这次开发过程中最大的感受就是自己之前 ...

  6. OO第二次博客作业(第二单元总结)

    在我开始写这次博客作业的时候,窗外响起了希望之花,由此联想到乘坐自己写的电梯FROM-3-TO--1下楼洗澡,然后······ 开个玩笑,这么辣鸡的电梯肯定不会投入实际使用的,何况只是一次作业.还是从 ...

  7. OO第二单元多线程电梯总结

    OO第二单元多线程电梯总结 第一次作业 设计思路 Input为输入线程,负责不断读取请求并将读到的请求放入调度器中. Dispatcher为调度器,是Input线程和Elevator线程的共享对象,采 ...

  8. [原][译][osg][osgEarth]飞行模拟软件JSBSim的操作(FGFCS类)

    英文原文在 FGFCS.h头文件中 JSBSim的控制操作封装了飞行控制系统(FCS)的功能. 这个FGFCS类还封装了相同的“系统”和“自动驾驶仪”能力. FGFCS包含用来定义一个系统或飞行模型体 ...

  9. OO第二单元の小结

    第二单元(线程与电梯问题)总结博客 三次作业的设计策略 第一次:本次作业只有一部电梯,而且不用捎带.因此,我一共设计了两个线程:一个负责管理输入,一个负责电梯运行.同时,我将调度队列设置为单例模式,里 ...

随机推荐

  1. 文件复制(shutil)

    import shutil #拷贝整个目录树 shutil.copytree('d:\\aaa','e:\\aaa') #目标文件夹(e:\aaa)必须不存在 shutil.rmtree('e:\\a ...

  2. Python学习---django模板继承180123

    django模板继承  --20180123 a.include 模板标签 b.extend(继承)模板标签 ------include 模板标签 该标签允许在(模板中)包含其它的模板的内容. 标签的 ...

  3. 申请MVP奖励时的小Tips

    大家新年好,今天MSPrecious为大家带来一些申请MVP奖励时的小Tips.   本文分为三个部分 MVP是什么 如何申请MVP 申请MVP需要注意的事项 MVP是什么? 我想,点进来看这篇文章的 ...

  4. scala当中的继承

    1.Scala中继承(extends)的概念 Scala 中,让子类继承父类,与 Java 一样,也是使用 extends 关键字: 继承就代表,子类可继承父类的 field 和 method ,然后 ...

  5. AngularJs学习笔记--Using $location

    原版地址:http://code.angularjs.org/1.0.2/docs/guide/dev_guide.services.$location 一.What does it do? $loc ...

  6. jq实现多级菜单

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  7. 寄存器简介 与 ebp esp

    http://www.cnblogs.com/zhuyuanhao/archive/2012/10/16/3262870.html 32位CPU所含有的寄存器有:4个数据寄存器(EAX.EBX.ECX ...

  8. 【转】实现Http Server的三种方法

    一.使用SUN公司在JDK6中提供的新包com.sun.net.httpserver JDK6提供了一个简单的Http Server API,据此我们可以构建自己的嵌入式Http Server,它支持 ...

  9. 卢卡斯定理Lucas

    卢卡斯定理Lucas 在数论中,\(Lucas\)定理用于快速计算\(C^m_n ~ \% ~p\),即证明\(C^m_n = \prod_{i = 0} ^kC^{m_i}_{n_i}\)其中\(m ...

  10. loadrunner脚本中参数化和返回值输出log到外部文件

    loadrunner脚本中参数化和返回值输出log到外部文件 很多时候,我们在做性能测试之前,需要造数据,但是使用的这些参数化数据和生成的返回数据在后面的测试都会用的,所以我们需要在造数据过程中,将参 ...