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. vue 项目中 js命名规则

    类型 规范 示例 常量 全字符大写,单词用 '_' 分隔 FETCH_USERS.GET_USERS 变量.函数 小写开头驼峰式 camelCase 类.特殊意义的命名空间 大写开头驼峰式 Camel ...

  2. 18. ClustrixDB 管理CPU资源

    作为一个分布式MPP数据库,ClustrixDB能够利用多个节点和核心来比单节点数据库更快地处理查询.有两个可调进程可以促进这一点. Clustrix选择了一组默认参数来控制那些提供最常见工作负载的进 ...

  3. vs中free内存失败

    关于vs中free内存失败: 主要有以下两个原因: 1. 函数参数调用写错.特别是传指针进去的时候,若形参与实参不对应,会出错. 2. 内存分配不够,这个原因主要是因为程序中访问到了内存外的地址,即使 ...

  4. html abbr标签 语法

    html abbr标签 语法 作用:标记一个缩写 大理石平台 说明:<abbr> 标签指示简称或缩写,比如 "WWW" 或 "NATO".通过对缩写 ...

  5. ELK+Filebeat+redis整合

    前面的博客,有具体的ELK安装配置步骤,此处在其基础上修改 修改配置文件并启动 [root@topcheer filebeat-6.2.3-linux-x86_64]# vim filebeat.ym ...

  6. 编译高博十四讲代码遇到依赖项g2o和cholmod的坑

    1. 找不到g2o库!在CMakeLists.txt中使用指令 message(STATUS "${G2O_FOUND}") 打印结果为NO. 问题描述: CMakeLists.t ...

  7. [BZOJ3796]Mushroom追妹纸:后缀自动机+KMP

    分析 这道题有个\(O(n)\)的后缀自动机做法,感觉很好理解就在这说一下. 先对\(s1\)和\(s2\)求最长公共子串,对于\(s2\)的每一个下标\(i\),求一个\(f[i]\)表示以\(s2 ...

  8. 测试常用linux命令之sed篇

    一.sed命令 可以放在单独的脚本文件中执行:sed -f script1 data1 多条命令也可以用{}括起来 sed可以进行文本的替换,删除,行添加,打印等.采用 sed [address]{c ...

  9. 1450:【例 3】Knight Moves

    1450:[例 3]Knight Moves  题解 这道题可以用双向宽度搜索优化(总介绍在  BFS ) 给定了起始状态和结束状态,求最少步数,显然是用BFS,为了节省时间,选择双向BFS. 双向B ...

  10. spring boot官方配置

    #BANNER banner.charset = UTF-8 #横幅文件编码.banner.location = classpath:banner.txt #横幅文件位置.banner.image.l ...