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

Author

ZHENG, Jianqiang

Source

ZJCPC2004

思路

就是很简单的模拟就好了

代码

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100000+10;
const int UP = 6;
const int DOWN = 4;
const int STAY = 5;
int a[MAXN]; int cal(int a[], int p)
{
int delta = a[p] - a[p-1];
int tmp = 0;
if(delta > 0)
tmp += delta * UP;
else
tmp += (-delta) * DOWN;
return tmp;
} //计算电梯相应的移动所需的时间
int main()
{
int n;
int ans;
while(cin>>n&&n!=0)
{
memset(a,0,sizeof(a));
ans = 0;
for(int i=1;i<=n;i++)
{
cin >> a[i];
ans += cal(a,i) + STAY;
}
cout << ans << endl;
}
}

Hdoj 1008.Elevator 题解的更多相关文章

  1. HDOJ 1008. Elevator 简单模拟水题

    Elevator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  2. hdoj 1008 Elevator

    Elevator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  3. Problem : 1008 ( Elevator )

    好操蛋啊,电梯竟然能原地不动,你大爷的,这逻辑,太弱智了.... Problem : 1008 ( Elevator )     Judge Status : Accepted RunId : 103 ...

  4. 1008 Elevator (20分)

    1008 Elevator (20分) 题目: The highest building in our city has only one elevator. A request list is ma ...

  5. PAT 1008. Elevator (20)

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

  6. PAT 1008 Elevator

    1008 Elevator (20 分)   The highest building in our city has only one elevator. A request list is mad ...

  7. PAT 甲级 1008 Elevator (20)(代码)

    1008 Elevator (20)(20 分) The highest building in our city has only one elevator. A request list is m ...

  8. PAT甲 1008. Elevator (20) 2016-09-09 23:00 22人阅读 评论(0) 收藏

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

  9. pat 1008 Elevator(20 分)

    1008 Elevator(20 分) The highest building in our city has only one elevator. A request list is made u ...

随机推荐

  1. Linux java 命令行编译 jar包

    Java 命令行编译成class,然后在打包成jar文件. 编译成class javac -classpath $CLASS_PATH -d class ./src/Hello.java 可以通过ja ...

  2. Vue-嵌套路由

    一个被渲染组件同样可以包含自己的嵌套 <router-view>.同样要有vue-router的三个要素:路由map .路由视图.路由导航. 举个在"/apple" 下 ...

  3. CF1146 Forethought Future Cup Elimination Round Tutorial

    CF1146 Forethought Future Cup Elimination Round Tutorial 叮,守夜冠军卡 https://codeforces.com/blog/entry/6 ...

  4. OpenDaylight(Oxygen)安装feature出现错误的解决方案

    在使用OpenDaylight控制器时,初次进入karaf命令行下都需要先进行feature的安装 在使用Nitrogen版本(0.7.x)时,组件的安装可以类似 feature:install od ...

  5. 《Linux内核设计与实现》第四章学习笔记

    <Linux内核设计与实现>第四章学习笔记           ——进程调度 姓名:王玮怡  学号:20135116 一.多任务 1.多任务操作系统的含义 多任务操作系统就是能同时并发地交 ...

  6. js 基础-&& || 逻辑与和逻辑或

    今天百度发现一个简化长if   else if 语句的方法,看起来及其强大,感觉这样虽然对系统性能提升没有帮助但是代码更简练了,分析了一番,下面先说说自己学到的理论. 首先要弄清楚js 中对于 变量, ...

  7. JUnit4 单元测试

    一. 题目简介 这次的单元测试我作了一个基本运算的程序,该程序实现了加,减,乘,除,平方,倒数的运算,该程序进行测试比较的简单,对于初步接触JUnit的我来说测试起来也比较容易理解. 二.源码的git ...

  8. iOS开发CAAnimation详解

    Core Animation,即为核心动画,它是一组非常强大的动画处理API,使用它能做出非常炫丽的动画效果,而且往往是事半功倍.也就是说,使用少量的代码就可以实现非常强大的功能.Core Anima ...

  9. sqlalchemy orm 操作 MySQL

    一.ORM介绍 orm英文全称object relational mapping,是对象映射关系程序,简单来说类似python这种面向对象的程序来说一切皆对象,但是我们使用的数据库却都是关系型的,为了 ...

  10. Online Resource Mapping for SDN Network Hypervisors using Machine Learning

    发表时间:2016 一些定义: self-configuring networks: FlowVisor: FlowVisor是建立在OpenFlow之上的网络虚拟化工具,它可以将物理网络划分成多个逻 ...