Elevator

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 73602    Accepted Submission(s): 40513

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
Problem : 1008 ( Elevator )     Judge Status : Accepted

RunId : 21242476    Language : G++    Author : hnustwanghe

Code Render Status : Rendered By HDOJ G++ Code Render Version 0.01 Beta

#include<iostream>
#include<cstring>
#include<cstdio>

using namespace std;

int main(){
int n,ans,last,now,i;
while(scanf("%d",&n)==1 &&n){
for(ans = last = 0,i=0;i<n;i++){
scanf("%d",&now);
if(now - last > 0){
ans += (now - last) * 6;
last = now;
}
else if(now - last < 0){
ans += (last - now) * 4;
last = now;
}
}
ans = ans + n*5;
printf("%d\n",ans);
}
}

#include<iostream>
#include<cstring>
#include<cstdio>

using namespace
std; int main(){
int
n,ans,last,now,i;
while(
scanf("%d",&n)==1 &&n){
for(
ans = last = 0,i=0;i<n;i++){
scanf("%d",&now);
if(
now - last > 0){
ans += (now - last) * 6;
last = now;
}
else if(
now - last < 0){
ans += (last - now) * 4;
last = now;
}
}

ans = ans + n*5;
printf("%d\n",ans);
}
}

思维体操: HDU1008 Elevator的更多相关文章

  1. 【ACM】HDU1008 Elevator 新手题前后不同的代码版本

    [前言] 很久没有纯粹的写写小代码,偶然想起要回炉再来,就去HDU随便选了个最基础的题,也不记得曾经AC过:最后吃惊的发现,思路完全不一样了,代码风格啥的也有不小的变化.希望是成长了一点点吧.后面定期 ...

  2. 思维体操: HDU1287破译密码

    破译密码 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  3. 思维体操: HDU1049Climbing Worm

    Climbing Worm Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  4. 思维体操: HDU1022Train Problem I

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. 解题报告:hdu1008 Elvator

    2017-09-07 19:30:22 writer:pprp 比较顺利,最近生活出现了各种问题, 发生了很多矛盾,我要耐下心来,最重要的不是努力不努力,而是选择 希望我能处理好人际关系还有学业上的压 ...

  6. 2.Web开发过程流程图

    转自:https://blog.csdn.net/hello_simon/article/details/19993343 最近公司在进行一系列新模块的开发,在痛苦开发的过程中,大家不时在一起进行总结 ...

  7. 题解-Koishi Loves Construction

    题解-Koishi Loves Construction 前缀知识 质数 逆元 暴搜 Koishi Loves Construction 给定 \(X\),\(T\) 组测试数据,每次给一个 \(n\ ...

  8. &&与||的优先级比较

    &&与||的优先级比较类似于一种思维体操,更多的是造成矛盾,使得两者因为先后顺序的不同而造成的不同结果,当然有时候需要注意c语言中的短路运算. 方法1. 代码如下: 点击查看代码 #i ...

  9. [C#][算法] 用菜鸟的思维学习算法 -- 马桶排序、冒泡排序和快速排序

    用菜鸟的思维学习算法 -- 马桶排序.冒泡排序和快速排序 [博主]反骨仔 [来源]http://www.cnblogs.com/liqingwen/p/4994261.html  目录 马桶排序(令人 ...

随机推荐

  1. 题解 CF1190B 【Tokitsukaze, CSL and Stone Game】

    思路: 首先题目告诉我们,一次只能删去一个石子.当然有翻译时会注意,但是看英文题时总是容易忽略.. 先排序. 然后,你会发现,有些情况是一开始就输的,具体情况如下: 有两个 两个相等非零数.(a[x] ...

  2. (转)python selenium-webdriver 元素操作之鼠标和键盘事件

    参考资料:https://blog.csdn.net/zh175578809/article/details/76767748 参考资料2:https://blog.csdn.net/qq_41817 ...

  3. mysql修改数据表某列的配置

    alter table 表名 modify column 字段名 类型;alter table 表名 drop column 字段名

  4. nginx利用try_files实现多个源

    比如一个视频网站,视频资源分散在几台机器上,但是给用要提供统一的IP,路径,端口.就需要nginx,先检查本机是否有改文件,如果没有就代理其他地方 location / { root /data/ww ...

  5. 【转】UNITY中相机空间,投影空间的正向问题

    原文链接1:https://www.cnblogs.com/wantnon/p/4570188.html 原文链接2:https://www.cnblogs.com/hefee/p/3820610.h ...

  6. vs2010 setup 打包 安装 BAT批处理实现自动安装软件功能

    CLS@echo offECHO.ECHO 安装 Diskeeper 7.0.428ECHO 请稍等...start /wait %systemdrive%\install\Applications\ ...

  7. Delphi XE2 之 FireMonkey 入门(34) - 控件基础: TFmxObject: 克隆对象

    Delphi XE2 之 FireMonkey 入门(34) - 控件基础: TFmxObject: 克隆对象 有两个和克隆相关的方法: Clone().CloneChildFromStream(). ...

  8. 【SpringMVC】---搭建框架步骤

    项目如下 一.加入 Jar 包 部分jar包可以不导(第4.9.11个可以不导入) 二.在 Web.xml 中配置 DispatcherServlet <?xml version="1 ...

  9. ContextLoader

    // // Source code recreated from a .class file by IntelliJ IDEA // (powered by Fernflower decompiler ...

  10. zstack分配的虚拟机的dns设置

    环境: $ uname -a Linux 10-57-19-61 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 x8 ...