题目描述

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. ContentPlaceHolderID属性

    用来对应包含与当前内容关联的 ContentPlaceHolder 的 ID啊 说白了就是去找母版页相应的ContentPlaceHolder ,然后把内容扔进那里面去 <asp:Content ...

  2. STM32F446 OTG_FS_DP/DM调试

    之前项目用STM32F207,现在升级到用STM32F446处理器,用到USB的OTG_FS模式接法: 1.USB只连接了DP/DM 2.DP需上拉1.5K的电阻到3.3V 3.PA9(VBUS) 和 ...

  3. liunx 内存文件 tmpfs

    tmpfs是Linux/Unix系统上的一种基于内存的文件系统.tmpfs可以使用您的内存或swap分区来存储文件 1 创建将被挂载的文件 mkdir /tmp/tmpfs/ 2 写入测试文件内容.大 ...

  4. launchMode传递参数注意startActivityForResult

    Activity1 到Activity2 用startActivityForResult 如果Activity2的launchMode为 singleInstance 和 singleTask 都会启 ...

  5. uIP学习笔记

    uIP学习笔记 从零开始使用uIP freemodbus modbus TCP 学习笔记

  6. 上海赛区-org.apache.ibatis.type.TypeException: JDBC requires that the JdbcType must be specified for all nullable parameters.

    执行此函数的时候报错 解决方法:关闭窗口之后刷新主页面 提示: 传入到xml sql语句中的参数为null时就会出现此错误,需要仔细检查

  7. c++内存流

    1.MemoryStream.h文件内容 ifndef _MEM_STREAM_H_ #define _MEM_STREAM_H_ #include <string> class CMem ...

  8. scull_p_read()函数分析

    /* * Data management: read and write */ static ssize_t scull_p_read (struct file *filp, char __user ...

  9. [转]intent 传递对象

    ---恢复内容开始--- Activity之间通过Intent传递值,支持基本数据类型和String对象及它们的数组对象byte.byte[].char.char[].boolean.boolean[ ...

  10. AI 人工智能 探索 (八)

    绑定下,用来释放内存 布局框架.链接:http://pan.baidu.com/s/1eQzSXZO 密码:25ir 这次 我采用 ngui 来设定界面.除工具栏模块外,其他各类ui模块都是 内存池动 ...