题目描述

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. bzoj1977

    1977: [BeiJing2010组队]次小生成树 Tree Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 3001  Solved: 751[Su ...

  2. SCANF SCANF_S

    今天在看C的教程的时候,用VS2013写了一小段代码 scanf("%f",&w); 提示需要在预编译器里添加 _CRT_SECURE_NO_WARNINGS,  百度了下 ...

  3. 第十六节,基本数据类型,字典dict

    字典 常用操作: 索引 新增 删除 键.值.键值对 循环 长度 字典由键值对组成,由一个键(名称)和 一个值组成,与列表和元组不同的是里面的元素是有键的(名称) 所以当要打印字典时,打印字典变量加[键 ...

  4. java 正则

    ava - 正则表达式 - Pattern - Matcher 2013-08-21 14:35 3325人阅读 评论(0) 收藏 举报  分类: JavaSE(30)  版权声明:本文为博主原创文章 ...

  5. storm 使用过程中遇到的问题

    1 bolt不停重启,excutor无法启动. nimbus日志类似如下(), 2014-03-12 10:55:06 b.s.d.nimbus [INFO] Executor MITAS3-74-1 ...

  6. laravel5.3初体验

    composer中已经推出了laravel5.3版本的安装依赖. 看到很多诱人的更新,今天决定尝试一下. 背景 操作系统:windows7 php:5.5.37 composer:1.1.3 1.首先 ...

  7. 对象之function

    开头啰嗦几句:程序之中,万事万物皆对象,这就是面向对象编程的核心思想,比如我们的js中的function,其实也是一个对象,是对象就可以有属性,在jq的源码中经常看到类似这样的方法: jQuery.E ...

  8. C++字符串(1)

    C++ 拼接字符串常量 C++允许拼接字符串字面值,即将两个用引号括起的字符串合并为一个.事实上,任何两个由空白(空格,制表符和换行符)分隔的字符串常量都将自动拼接成一个. 例子: cout < ...

  9. C++中的基本数据类型

    C++中定义了一组表示整数.浮点数.单个字符和布尔值的算术类型(arithmetic type). 另外还定义了一种叫做void的特殊类型.void类型没有对应的值,仅用在有限的一些情况下,通常用作无 ...

  10. Ztree当节点没有下级时不显示下拉图标

    select o.*,(select count(*) from sys_org t where t.orgsupid=o.orgid) isLeaf from sys_org o where 1=1