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. full join 时通过辅助列序号列消除笛卡尔积重复列

    如果没有序号列,那么如果领灯表里有3条数据,还灯表里面有2条数据,full join后就是3*2=6条数据 --1.领灯表,每天每班每人允许重复数据 select ID ,ROW_NUMBER() o ...

  2. fabric自动发布tomcat线上项目

    现在公司的每个tomcat项目都有测试和生产两个环境,对于经常需要上线的tomcat项目,如用手工更新就非常耗费时间和人力.现用fabric开发了一个自动发布tomcat项目的脚本,该脚本已经在公司使 ...

  3. 数据结构之shell排序

    #SIZE  10        //直接插入排序     void insert_sort(){           int i,j;           int array[SIZE+1];   ...

  4. 钩子编程(HOOK) 安装进程内键盘钩子 (1)

    摘要:钩子能够监视系统或进程中的各种事件消息.截获发往目标窗体的消息并进行处理.这样,我们就能够在系统中安装自己定义的钩子,监视系统中特定事件的发生.完毕特定的功能,比方截获键盘.鼠标的输入.屏幕取词 ...

  5. DDD中的聚合和UML中的聚合以及组合的关系

    UML:聚合关系:成员对象是整体的一部分,但是成员对象可以脱离整体对象独立存在.如汽车(Car)与引擎(Engine).轮胎(Wheel).车灯(Light)之间的关系为聚合关系,引擎.轮胎.车灯可以 ...

  6. 启动spring boot 异常

    再我搭建spring boot工程后,run application的时候抛出下面异常 Exception /slf4j-log4j12-.jar). If you are using WebLogi ...

  7. Weka学习之关联规则分析

    步骤: (一) 选择数据源 (二)选择要分析的字段 (三)选择需要的关联规则算法 (四)点击start运行 (五) 分析结果 算法选择: Apriori算法参数含义 1.car:如果设为真,则会挖掘类 ...

  8. 机器学习2—K近邻算法学习笔记

    Python3.6.3下修改代码中def classify0(inX,dataSet,labels,k)函数的classCount.iteritems()为classCount.items(),另外p ...

  9. Hibernate 中的DetachedCriteria。

    今天看到项目中在Web层使用DetachedCriteria进行多条件查询操作,如果在web层做持久层操作,事物还存在吗?这是我第一反应,于是乎就去网上查资料了.结果发现即在web层,程序员使用Det ...

  10. 嵌入式开发之字符叠加---gb2313 国标码,utf8 国际码,unicode 无码

    (1)国标码简介 (2)编码转换 (3)时间获取 (4)显示切换 最近做了个字符叠加,包括时间叠加,字符中文叠加,位置移动,等功能开启.因为一般的字符叠加的点阵式16位,然后填充着16位的编码是gb2 ...