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. Luogu4630 APIO2018 Duathlon 圆方树、树形DP

    传送门 要求的是一条按顺序经过\(s,t,c\)三个点的简单路径.简单路径的计数问题不难想到点双联通分量,进而使用圆方树进行求解. 首先将原图缩点,对于一个大小为\(size\)的点双联通分量内,在这 ...

  2. vue 动态加载组建

    <component :is="comp1"></component> data () { return { comp1:'', } } require.e ...

  3. 验证码处理类:UnCodebase.cs + BauDuAi 读取验证码的值(并非好的解决方案)

    主要功能:变灰,去噪,等提高清晰度等 代码类博客,无需多说,如下: public class UnCodebase { public Bitmap bmpobj; public UnCodebase( ...

  4. JVM规范系列第6章:Java虚拟机指令集

    一条 Java 虚拟机指令由一个特定操作的操作码和零至多个操作所使用到的操作数所构成. 虚拟机指令 = 操作码 + 操作数. 其中,操作码值分别为 254(0xfe)和 255(0xff),助记符分别 ...

  5. C#编程:从控制台读取数字的两种方式

    有时需要从控制台输入数字,就用到前面介绍的内容,数据转换,如:int num=int.Pares(Console.ReadLine()); int num=Convert.ToInt32(Consol ...

  6. TCP服务端开发为例--web开发不同url请求为何会走不同方法

    拿java的web开发为例子,相信有很多小伙伴是做j2EE开发的,htpp请求,json数据传输都是工作中经常用的,查询请求,添加请求,修改请求前端配个url,例如https://localhost/ ...

  7. Centos下安装破解confluence6.3的操作记录

    confluence是一个专业的企业知识管理与协同软件,可以用于构建企业wiki.通过它可以实现团队成员之间的协作和知识共享.现在大多数公司都会部署一套confluence,用作内部wiki.现在co ...

  8. 置换群 Burnside引理 Pólya定理(Polya)

    置换群 设\(N\)表示组合方案集合.如用两种颜色染四个格子,则\(N=\{\{0,0,0,0\},\{0,0,0,1\},\{0,0,1,0\},...,\{1,1,1,1\}\}\),\(|N|= ...

  9. 饿了么element UI<el-dialog>弹出层</el-dialog>修改默认样式不能在<style scoped>修改

    如果在非scoped下,修改el-dialog自动添加的DIV类名的style加上important,可以覆盖原来的width,但这样会让整个项目的样式都乱套. 如果在scoped下修改style.所 ...

  10. 【个人总结】软件工程M1/M2总结

    个人博客连接: http://www.cnblogs.com/lwq12061168/p/4094252.html http://www.cnblogs.com/lwq12061168/p/40284 ...