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. leetCode 15. 3Sum (3数之和) 解题思路和方法

    3Sum  Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find ...

  2. Mongodb 的学习

    传送门: # 官方网站 及 下载地址 https://www.mongodb.com/download-center/enterprise/releases # 之前简单学习的笔记http://www ...

  3. springboot整合docker部署(两种构建Docker镜像方式)

    项目结构 package hello; import org.springframework.boot.SpringApplication; import org.springframework.bo ...

  4. ANDROID L——Material Design具体解释(主题和布局)

    转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990).谢谢支持! Android L: Google已经确认Android L就是Android Lolli ...

  5. SQL 时间格式转换

    ------- 获取当前时间 -------- DECLARE @currentTime varchar(); SET @currentTime = CONVERT(VARCHAR(),GETDATE ...

  6. oracle字符乱码的解决方法

    原因分析: 客户端字符集就是为了让数据库知道我们传递过去的字符是属于哪种字符集,以便于Oracle在存储字符时进行相应的编码映射(查看客户端字符集通过查找注册表中的NLS_LANG键).在客户端查询数 ...

  7. nginx http proxy 正向代理

    配置 Nginx Http Proxy 代理服务器,与 [Squid] 功能一样,适用于正向代理 Http 网站. 一,Nginx 正向代理配置文件: server { resolver 8.8.8. ...

  8. str_replace 替换 小技巧

    // $id:1 $id:1,2,3,4,5 public function delete($id) { // 把1替换掉不允许删除ID为1的角色             在前面分别加了 , 号   ...

  9. 嵌入式驱动开发之sensor---sensor 图形传感器调试

    图像传感器(image sensor)复位顺序 1. 硬件复位寄存器:2. 软件复位寄存器:3. 设置时钟寄存器:4. 设置PLL倍频:5. 设置分辨率:6. 设置窗口控制:7. 设置输出顺序:8. ...

  10. Windows下搭建React Native Android开发环境

    准备工作 安装JDK 安装Android SDK 安装C++环境 安装node.js 安装react-native命令行工具 创建项目 运行packager 运行模拟器 安卓运行 安卓调试 安装JDK ...