题目描述

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

题目大意

简单的水题,电梯上升一层楼需要6s,下降需要4s,到达目的楼层后停留5s。给出目的楼层的列表。求需要的时间。

使用模拟法,模拟电梯的运行过程求得总时间。

AC代码

  1. #include<iostream>
  2. #include<stdio.h>
  3. using namespace std;
  4. int main()
  5. {
  6. //freopen("date.in","r",stdin);
  7. //freopen("date.out","w",stdout);
  8. ios::sync_with_stdio(false);
  9. int N,m,sum,tem;
  10. while(cin>>N&&N!=0)
  11. {
  12. sum=0;
  13. tem=0;
  14. for(int i=0;i<N;i++)
  15. {
  16. cin>>m;
  17. if(m>tem)
  18. sum+=(6*(m-tem));
  19. else sum+=(4*(tem-m));
  20. tem=m;
  21. }
  22. cout<<sum+N*5<<endl;
  23. }
  24. }

SDAU课程练习--problemG(1006)的更多相关文章

  1. SDAU课程练习--problemQ(1016)

    题目描述 FJ is surveying his herd to find the most average cow. He wants to know how much milk this 'med ...

  2. SDAU课程练习--problemO(1014)

    题目描述 Before bridges were common, ferries were used to transport cars across rivers. River ferries, u ...

  3. SDAU课程练习--problemB(1001)

    题目描述 There is a pile of n wooden sticks. The length and weight of each stick are known in advance. T ...

  4. SDAU课程练习--problemA(1000)

    题目描述 The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape i ...

  5. SDAU课程练习--problemC

    题目描述 Here is a famous story in Chinese history. "That was about 2300 years ago. General Tian Ji ...

  6. SDAU课程练习--problemE

    problemE 题目描述 "今年暑假不AC?" "是的." "那你干什么呢?" "看世界杯呀,笨蛋!" "@ ...

  7. SpringMVC框架 课程笔记

    SpringMVC框架 课程笔记 第0章 SpringMVC框架的核心内容 1.SpringMVC 概述 2.SpringMVC 的 HelloWorld 3.使用 @RequestMapping 映 ...

  8. MyBatis框架 课程笔记

    MyBatis框架 课程笔记   第1章 MyBatis简介 1.1 MyBatis历史 1)MyBatis是Apache的一个开源项目iBatis, 2010年6月这个项目由Apache Softw ...

  9. .NET 提升教育 第一期:VIP 付费课程培训通知!

    为响应 @当年在远方 同学的建议,在年前尝试进行一次付费的VIP培训. 培训的课件:点击下载培训周期:10个课程左右,每晚1个半小时培训价格:1000元/人.报名方式:有意向的请加QQ群:路过秋天.N ...

随机推荐

  1. 将GridView导入到Excel

    前几天做项目需要用到将GridView中的数据导入到Excel,原以为很简单,上网搜了一下资料,果然方法不少,于是就采用了一个: private void GridViewToExcel() { Re ...

  2. MYSQL超时连接问题(com.mysql.jdbc.MysqlIO.readFully)

    应用服务器连接mysql,有时候会出现以下异常: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.jav ...

  3. akka 入门

    http://blog.csdn.net/thkhxm/article/details/40182835 1.首先安装akka的相关包-- http://akka.io/downloads/2.导入依 ...

  4. hdu_2608_0 or 1_数论

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2608 反正我是没找出这个规律的,规律参考的别人的! /* 分析:假设数n=2^k*p1^s1*p2^s ...

  5. string的数值转换

    to_string(val); //数值val的string表示 stoi (s, p, b); stol (s, p, b); stoul (s, p, b); stoll (s, p, b); s ...

  6. PHP详解$_SEVER常用变量

    $_SERVER['HTTP_ACCEPT_LANGUAGE']//浏览器语言 $_SERVER['HTTP_ACCEPT'] //当前请求的Accept头部的内容,例如text/html,appli ...

  7. Linux下 Unison 实现文件双向同步

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://hx100.blog.51cto.com/44326/612301 一.Uniso ...

  8. IOS tableViewCell单元格重用中的label重叠的问题

    参考:http://zhidao.baidu.com/link?url=_oMUTo5SxUY6SBaxYLsIpN3i2sZ6SKG35MVlPJd2cNmUf9TGQFkKXX9EXwSwti0n ...

  9. Oracle where 0=1 or 1=1

    本文转载自:http://www.cnblogs.com/junyuz/archive/2011/03/10/1979646.html sql where 1=1和 0=1 的作用   where 1 ...

  10. JNI调用问题(部分机型崩溃)

    1.今日测试发现在部分手机上游戏会崩溃,通过logcat日志发现是jni调用问题(我猜测) 错误日志中有如下语句: trying to work around app JNI bugs, but di ...