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. GET和POST请求的区别和使用场景

    本质上的区别: GET请求.处理.响应过程中只是产生一个TCP数据包,而POST请求会产生两个TCP数据包.    更具体地说,GET请求过程中头和请求正文数据一起到服务器端, 而POST请求过程中, ...

  2. GO语言学习笔记1-输入带空格的字符串

    最近开始学习GO语言,并做了一些编程练习.有道题要输入带空格的字符串,这在C/C++中很容易实现,但GO中好像并不那么容易.学过C/C++的可能都知道,在C中可以使用gets()函数,在C++可以使用 ...

  3. Vue组件创建和组件传值

    Vue创建组件的方式 使用Vue.Extend()和Vue.component全局注册组件 首先我们定义一个组件并接收 var com1 =Vue.extend({ template:"&l ...

  4. Maven手动命令行导入ojdbc6

    Maven项目中导入Oracle的驱动包时,可能会出现像我一样下载资源不成功的情况,如下图所示:  出现这种情况的原因其实是因为Oracle的授权问题,这样的话,我们在需要使用Oracle的驱动包时, ...

  5. docker-compose部署ELK(亲测)

    具体的配置可以参考上面一篇:docker部署ELK 以下是做了一些修改的地方: kibana.yml [root@topcheer config]# cat kibana.yml server.hos ...

  6. mac osx终端批量删除文件

    sudo su cd / find ./ -name "*.html" -exec rm -rf {} \;  注意 {}和\;之间有空格 find [目录名] -name &qu ...

  7. HDU6025 Coprime Sequence(gcd)

    HDU6025 Coprime Sequence 处理出数列的 \(gcd\) 前缀和后缀,删除一个数后的 \(gcd\) 为其前缀和后缀的 \(gcd\) . 遍历数列取 \(max\) 即为答案. ...

  8. SpringMvc配置自定义视图

    1.在dispatcherServlet-servlet.xml配置自定义视图 <!-- 配置视图 BeanNameViewResolver 解析器: 使用视图的名字来解析视图 --> & ...

  9. leetcode 287寻找重复数

    这道题用STL容器就很好写了,可以用set也可以用map, 用unordered_map的C++代码如下: class Solution { public: int findDuplicate(vec ...

  10. node.js ffmpeg-concat 命令行形式处理多个视频的过度效果

    ffmpeg-concat 是利用 gl-transitions 处理多个视频的过度效果.详细说明参见 https://github.com/transitive-bullshit/ffmpeg-co ...