博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Elevatorhdu-1008
阅读量:4561 次
发布时间:2019-06-08

本文共 1380 字,大约阅读时间需要 4 分钟。

Elevator

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 33731    Accepted Submission(s): 18412

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

#include<stdio.h>

int main()

{

    int n,i,j,k,a[120];

    while(scanf("%d",&n)&&(n!=0))

    {

      a[0]=0;

      for(i=1,k=0;i<=n;i++)

      {

        scanf("%d",&a[i]);

        if(a[i]>a[i-1])

        k=k+(a[i]-a[i-1])*6;

        else

        k=k+(a[i-1]-a[i])*4;

      }

      printf("%d\n",k+n*5);

    }

    return 0;

}

转载于:https://www.cnblogs.com/zhouhongweihpu/p/3217382.html

你可能感兴趣的文章
制表符 \t 的用法
查看>>
断点模式
查看>>
ubuntu 下安装微软字体和 console
查看>>
Ubuntu 侧边栏和顶栏设置
查看>>
如何修改 ubuntu系统中shell中命令行起始的@符号后面的字符
查看>>
了解数据产品经理
查看>>
Chromium被用于Microsoft Edge与ChakraCore的未来【译】
查看>>
C# 序列化与反序列化
查看>>
Ubuntu的一些文件系统的操作(转自我自己的其他博客)
查看>>
python学习中的bug
查看>>
多线程(3)
查看>>
sizeof(即类型大小)详解-转自http://veryti.com/question/443
查看>>
[恢]hdu 1005
查看>>
SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问 ....
查看>>
views_object / views_db_object
查看>>
静态缓存
查看>>
在线编辑器ckeditor配置与使用
查看>>
出圈问题C++源码(STLVector)
查看>>
instanceof语法解释
查看>>
计算字符串的高度
查看>>