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. BZOJ4816 SDOI2017 数字表格 莫比乌斯反演

    传送门 做莫比乌斯反演题显著提高了我的\(\LaTeX\)水平 推式子(默认\(N \leq M\),分数下取整,会省略大部分过程) \(\begin{align*} \prod\limits_{i= ...

  2. 格式化angularjs日期'/Date(-62135596800000)/'

    在实现在angularjs时,发现经序列化后的日期需要格式化显示. 翻看以前的博客,似乎有写过一篇有关js方面的解决办法<格式化json日期'/Date(-62135596800000)/'&g ...

  3. 以英雄联盟的方式建模,谈对依赖注入(DI)的理解以及Autofac的用法(一)

    一.前言 近期在探索分层架构和架构设计,选择了领域驱动作为5年.Net开发后的新的方向,不可避免的接触了IoC/DI方面的技术.目前通过反射或其他方法都已实现,但只知其一,并没有考虑为什么要这么做,同 ...

  4. 基于Nginx+Keepalived的LB服务监控(邮件报警)

    IDC两台机器上部署了Nginx+Keepalived主从模式的LB代理负载层,现在需要对LB进行每日巡检和服务监控,利用SendEmail邮件监控. 0)SendEmail部署 参考:http:// ...

  5. Linux下开源邮件系统Postfix+Extmail+Extman环境部署记录

    一.基础知识梳理MUA (Mail User Agent) MUA 既是"邮件使用者代理人",因为除非你可以直接利用类似 telnet 之类的软件登入邮件主机来主动发出信件,否则您 ...

  6. Linux系统下本地yum镜像源环境部署-完整记录

    之前介绍了Linux环境下本地yum源配置方法,不过这个是最简单最基础的配置,在yum安装的时候可能有些软件包不够齐全,下面说下完整yun镜像源系统环境部署记录(yum源更新脚本下载地址:https: ...

  7. 基于 CentOS 搭建 FTP 文件服务

    https://www.linuxidc.com/Linux/2017-11/148518.htm

  8. js实现树形内容展示

    1.首先这里有一个demo,里边有封装好的js文件.地址:http://files.cnblogs.com/files/feifeishi/dtree.zip 2.直接上代码 <div styl ...

  9. suqid透明正向代理

    如果想实现透明正向代理,则必需将用户的网关IP指向 Squid 服务器,而此后便无需再修改浏览器选项 在命令行 <菜单+R> 中使用 ping  命令: ping  www.baidu.c ...

  10. Red Hat 5.8 CentOS 6.5 共用 输入法

    pick up from http://jingyan.baidu.com/article/20b68a885a3607796cec622c.html