HDOJ1008

题目

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

代码

#include<stdio.h>
int main()
{int N, i, n, n1, time;while(~scanf("%d", &N)&&N!=0){time = 0;n1 = 0;for(i=0;i<N;i++){scanf("%d", &n);if(n>n1){time += (n-n1)*6;              //up}else{time += (n1-n)*4;             //down}n1 = n;}time = time+5*N;printf("%d\n", time);}
}

Conclusion
这道题只要把题意理解清楚就很简单。我一开始还傻乎乎的以为电梯每层都要停5s。。。

HDOJ1008 Elevator相关推荐

  1. XTUOJ 1206 Dormitory's Elevator

    Dormitory's Elevator Time Limit : 1000 MS   Memory Limit : 65536 KB Problem Description The new dorm ...

  2. 一个IO的传奇一生(8) -- elevator子系统

    Elevator子系统介绍 Elevator子系统是IO 路径上非常重要的组成部分,前面已经分析过,elevator中实现了多种类型的调度器,用于满足不同应用的需求.那么,从整个IO路径的角度来看,e ...

  3. PAT甲级1008 Elevator:[C++题解]模拟

    文章目录 题目分析 题目来源 题目分析 来源:acwing 分析:统计上升次数.下降次数:停留次数就是n.然后算数即可. ac代码 #include<bits/stdc++.h> usin ...

  4. XTU Dormitory's Elevator(动态规划)

    Dormitory's Elevator Accepted : 70   Submit : 394 Time Limit : 1000 MS   Memory Limit : 65536 KB Pro ...

  5. [0715]Jsoi Test elevator

    elevator 时间限制:1秒  内存限制: 64 MB 试题描述 夏令营报到结束了,回到宿舍干什么呢?根据教练员的安排,大家只能讨论一些往年JSOI夏令营的老题目.于是,N次参加夏令营的小X同学立 ...

  6. 用Elevator优化AV1视频播放

    AOM会员Vimeo通过Elevator改善AV1解码过程中的丢帧和质量下降问题.感谢Google软件工程师姜健对本文做的技术审校. 文 / Raphaël Zumer 译 / 刘俊 技术审校 / 姜 ...

  7. 1008 Elevator (20 分)_13行代码AC

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 The highest building in our city has only one elevator. A request ...

  8. By Elevator or Stairs? CodeForces - 1249E(动态规划)

    题意 n层楼,a[i] (0<i<n)表示从 i 楼到 i + 1 楼走楼梯的时间,b[i] (0<i<n)表示从 i 楼到 i + 1 楼乘电梯的时间,其中每一次乘电梯需要等 ...

  9. 1008. Elevator (20)

    1008. Elevator (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The highest ...

  10. 【POJ - 2392】Space Elevator (dp,优秀的背包问题)

    题干: The cows are going to space! They plan to achieve orbit by building a sort of space elevator: a ...

最新文章

  1. 2020各省份大学排名出炉!
  2. 第一篇博客——ACM之路!
  3. python字典经典例题_python 字典(Dictionary)的一些内置函数和经典例题
  4. MariaDB的二进制包安装方法
  5. 【luogu P1343 地震逃生】 题解
  6. Java领域的对象如何传输-如何解决报错的问题呢?
  7. 励志!送女儿去厦大读研后,爸爸回家就考了厦大的博士,现在是女儿的“学弟”...
  8. 高仿wx钱包页H5网站源码
  9. java boolean 包_java Boolean包装类工作笔记
  10. 【转载】关于.NET下开源及商业图像处理(PSD)组件
  11. unix服务器上传文件,Unix lrzsz命令 上传本地文件到服务器 / 发送文件到客户端...
  12. c++矩阵库eigen的使用方法
  13. Exchange使用正常的恢复无法恢复的问题
  14. 【Elasticsearch】高亮查询 highlighting (一)
  15. 机器学习(Machine Learning)深度学习(Deep Learning)较全面的资料
  16. 游戏能给QQ一个未来吗?
  17. Markdown基本语法(摘录)
  18. AI洞观 | 一文读懂2018安博会四大趋势
  19. 期权希腊值之delta【python复现】
  20. 中煤集团公司硬件扩容与数据库迁移项目实施方案

热门文章

  1. java web聊天室原理_网页聊天室的原理
  2. 24位真彩色bmp图片转8位256色带调色板的bmp图
  3. 林文信12小时学会流行键盘基础教程-爱奇艺链接地址
  4. 移动技术--从网页游戏谈起 1
  5. 惠普打印机驱动服务器系统安装步骤,Win8.1安装惠普打印机驱动程序的两种方法...
  6. FRED应用:锥透镜的设计
  7. 编译libfetion时,提示 从 int 到 QString 的转换有歧义
  8. 解决:Please either set ERLANG_HOME to point to your Erlang installation or place the RabbitMQ server d
  9. 机器视觉——相机标定(摄像机标定)
  10. 博弈论个人的一点小总结