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. 模型层(template)

    错误之forbbiddon csrf_token:这个标签用于跨站请求伪造保护 提交数据的时候就会做安全机制,当你点击提交的时候会出现一个forbbiddon 的错误,就是用setting配置里的sc ...

  2. 将旧的时间字符串转换为新的string时间字符串

    旧的时间字符串-->simpledataformat1.parse(该字符串) 获得date类型 -->simpledataformat2.format(date) simpledatef ...

  3. December 12th 2016 Week 51st Monday

    Nothing is impossible for a willing heart. 心之所愿,无所不成. I wish I can be a strong, clever, powerful and ...

  4. Linux中配置ftp服务器

    1. 先用rpm -qa| grep vsftpd命令检查是否已经安装,如果ftp没有安装,使用yum  -y  install vsftpd 安装,(ubuntu 下使用apt-get instal ...

  5. MySQL查询时强制区分大写和小写

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/zyb_icanplay7/article/details/24981791 平时非常少会考虑数据存储 ...

  6. Guava包学习--Multiset

    Multiset之前倒是没用过,后来看了下还挺有用,其实它就是支持重复元素的HashSet,相当于list+set的集合,综合了两种集合的优点. 它扩展了Collection: @GwtCompati ...

  7. jQuery UI 实例 – 切换(Toggle)

    toggle()函数用于为每个匹配元素的click事件绑定轮流的处理函数. toggle()是一个特殊的事件函数,用于为匹配元素的click事件绑定多个事件处理函数.每次触发click事件时,togg ...

  8. POJ2187 Beauty Contest(旋转卡壳)

    嘟嘟嘟 旋转卡壳模板题. 首先求出凸包. 然后\(O(n ^ 2)\)的算法很好想,但那就不叫旋转卡壳了. 考虑优化:直观的想是在枚举点的时候,对于第二层循环用二分或者三分优化,但实际上两点距离是不满 ...

  9. linq查询语法和方法-簡單用法

    來自:http://www.cnblogs.com/knowledgesea/p/3897665.html 1.简单的linq语法 //1 var ss = from r in db.Am_recPr ...

  10. POJ 1703 Find them, Catch them(确定元素归属集合的并查集)

    Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 52925   Accepted: ...