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. 参数类型*&是什么意思?

    前两天摸鱼聊天的时候遇到一个问题,一个链表的函数中,有一个参数显得很奇怪 (大概是一个样子的)ListNode<T>*& l 这个参数l除了用了一个*之外还用了一个&,直觉 ...

  2. PISCES: A Programmable, Protocol-Independent Software Switch

    Name of article:PISCES: A Programmable, Protocol-Independent Software Switch Origin of the article:S ...

  3. AIDL在android系统中的作用

    AIDL,Android Interface definition language的缩写,它是一种android内部进程通信接口的描述语言,通过它我们可以定义进程间的通信接口.最近看了下AIDL在A ...

  4. (转载)Kaggle_Titanic生存预测 -- 详细流程吐血梳理

    Kaggle_Titanic生存预测 -- 详细流程吐血梳理 https://blog.csdn.net/Koala_Tree/article/details/78725881 Kaggle中Tita ...

  5. legend2---lamp.sh一键安装lamp环境需要爬的坑

    legend2---lamp.sh一键安装lamp环境需要爬的坑 一.总结 一句话总结: 1.要记得更改项目权限:chown -R apache:apache /data/www/default/网站 ...

  6. shell脚本之浮点数和整数计算

    整数计算 直接使用放括号计算即可,省去*号需要使用转义符的麻烦 #!/bin/bash num1= num2= var1=$[ $num1 * $num2 ] echo "$var1&quo ...

  7. C++中cout输出字符串和字符串型指针地址值的方法以及C语言中的printf用法比较

    #include <iostream> using namespace std; #include <stdio.h> int main() { char *pstr = &q ...

  8. 双三次插值C代码(利用opencv)

    双三次插值C代码(利用opencv) phasecubic2.cpp D:\文件及下载相关\文档\Visual Studio 2010\Projects\phasecubic2\phasecubic2 ...

  9. 安装 Windows 系统在 NVMe 规范的 M.2 接口的固态硬盘(SSD)上

    作为一个程序员很重要的一项技能就是装系统 @_@,以前我都是随便用网上的工具做个系统盘,每次要用直接随手就搞好了,节省大家时间. 但最近同事装了个贼小的固态,然后我启动盘里的系统果断识别不出来他的固态 ...

  10. 用configmap管理配置

    一.ConfigMap介绍管理配置: ConfigMap介绍 Secret 可以为 Pod 提供密码.Token.私钥等敏感数据:对于一些非敏感数据,比如应用的配置信息,则可以用 ConfigMap ...