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
 
Sample Way
 

#include <stdio.h>
#include <stdlib.h>

int main()
{
  int n,i,sum,floor[100]={0};
  while(scanf("%d",&n)==1&&n!=0)
  {
  sum=0;
  for(i=1;i<=n;i++)
  {
  scanf("%d",&floor[i]);
  }
  for(i=1;i<=n;i++)
  {
  if(floor[i]>floor[i-1]) sum+=(floor[i]-floor[i-1])*6;
  if(floor[i]<floor[i-1]) sum+=(floor[i-1]-floor[i])*4;
  }
  printf("%d\n",sum+n*5);
  }
  return 0;
}

 

hd acm1008的更多相关文章

  1. ATI Radeon HD 5450 with full QE/CI Support ( 转载 )

    ATI Radeon HD 5450 with full QE/CI Support - DSDT (Contains HDMI Audio Edit Too) & AGPM included ...

  2. XPS 15 9530使用Windows10频繁发生Intel HD Graphics 4600驱动奔溃的一种解决方法

    本人使用XPS 15 9530.集成显卡为Intel HD Graphics 4600.操作系统Windows 10 Pro,使用过程当中经常会发生集成显卡奔溃的问题,错误提示如下: Display ...

  3. Radeon HD 7850 vs Radeon R9 270X

    Radeon HD 7850 vs Radeon R9 270X  HW compare   Intro The Radeon HD 7850 comes with a GPU core speed ...

  4. 电影TS、TC、SCR、R5、BD、HD等版本是什么意思

    在很多电影下载网站的影片标题中我们都能看到,比如<刺杀希特勒BD版>.<游龙戏凤TS版>等,这些英文缩写都是什么意思呢?都代表什么画质?以下就是各个版本的具体含义: 1.CAM ...

  5. stm32类型cl、vl、xl、ld、md、hd的含义

    - startup_stm32f10x_ld_vl.s: for STM32 Low density Value line devices - startup_stm32f10x_ld.s: for ...

  6. 瑞昱Realtek(Realtek HD Audio Driver)音频声卡驱动R2.49 for Win7_Vista

    不管是在高端系列主板上,还是在低端系列主板上,我们都能看到Realtek瑞昱的身影,Realtek HD Audio Driver能够支持所有的Realtek HD Audio音频驱动.Realtek ...

  7. cocos2d-x 2.0.3 设置高清模式注意事项(已移除-hd方式)

    猴子原创,欢迎转载.转载请注明: 转载自Cocos2D开发网–Cocos2Dev.com,谢谢! 原文地址: http://www.cocos2dev.com/?p=304 在cocos2d-x 2. ...

  8. %hd %d %ld %u ......

    %d 有符号10进制整数 %ld 长整型 %hd短整型%md,m指定的是输出字段的宽度,默认左补空格, 如果数据的位数小于m,则左端补以空格,若大于m,则 按实际位数输出,如: printf(&quo ...

  9. 求刷Kindle Fire HD的方法

    前几天入手了台Amazon Kindle Fire HD 其系统是经过Amazon尝试改造过的Android,用起来很不爽,想刷个CM10之类的,求教程和工具.

随机推荐

  1. ASP.NET CORE RAZOR :向 Razor 页面添加验证

    https://docs.microsoft.com/zh-cn/aspnet/core/tutorials/razor-pages/validation 本部分中向 Movie 模型添加了验证逻辑. ...

  2. ArcObject IFeature set_Shape()和Delete()报错

    这样的问题主要是Ifeature实际在数据库里面不存在!可是通过IFeatureClass.getFeature()又可以得到! 详细操作流程: 首先是对要素进行删除,可是通过IFeatureClas ...

  3. SpringBoot使用Thymeleaf模板

    © 版权声明:本文为博主原创文章,转载请注明出处 Thymeleaf模板简介 Thymeleaf模板是一个现代化的服务端java模板引擎对于所有的web和独立环境 Thymeleaf的主要目标是为你的 ...

  4. java消息中间件之ActiveMQ初识

    目录 消息中间件简介 解耦合和异步 可靠性和高效性 JMS P2P Pub/Sub AMQP JMS和AMQP对比 常见消息中间件 ActiveMQ RabbitMQ Kafka 综合比较 标签(空格 ...

  5. 自己定义控件三部曲视图篇(二)——FlowLayout自适应容器实现

    前言:我最大的梦想,就是有一天.等老了坐在摇椅上回望一生,有故事给孩子们讲--. 相关文章: <Android自己定义控件三部曲文章索引>:http://blog.csdn.net/har ...

  6. Apache + Tomcat集群 + 负载均衡

    Part I: 取经处: http://www.ramkitech.com/2012/10/tomcat-clustering-series-simple-load.html  http://blog ...

  7. nginx反向代理做cache配置

    前序:请耐性子看完,前面的这个配置可以达到按后缀名进行缓存,但无法被purge.后面的配置可以被purge.具体实施方案按个人情况而定. 需要第三方的ngx_cache_purge模块:wget ht ...

  8. do{}while(0)与CC_BREAK_IF的绝妙搭配

    从一開始认为没有必要,到认为很好用.我经历了大概两个月的时间,以下来总结一下什么情况下使用这样的结构吧. 第一种情况:当载入文件的时候,假设载入文件失败,须要报错的时候. 当前,能够用try{}cat ...

  9. win10下VS2010中文输入法切换为英文卡死

    中文输入法下输入英文,VS2010会出现卡顿现象,之后会出现一大串的重复英文字母. win10下VS2010安装的助手VAssit系统不兼容,而win7下不会出现上述问题. 解决办法:卸载安装的助手V ...

  10. Linux中的提示符

    root的提示符:# 一般用户的提示符:$