hdoj-1008-Elevator(解题报告)

该博客详细介绍了HDU 1008题目的解题过程,涉及电梯在不同楼层间的运行时间计算。电梯上行一层需6秒,下行一层需4秒,每层停留5秒。博主分析了题目,并提出解题思路,即根据输入数据计算电梯运行总时间,考虑电梯上行和下行的不同速度以及停留时间。
摘要由CSDN通过智能技术生成

题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1008

问题描述:

Elevator

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 70908    Accepted Submission(s): 38941


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

Author

ZHENG, Jianqiang
 

题目分析:电梯向上一层需要6秒,向下一层需要4秒,每层停5秒,问电梯按输入顺序运行,每组数据需要多少秒实现。

解题思路:根据输入输出数据可知,电梯默认从第0层开始运行,每组数据先输入一个数代表电梯共停几次,再进行计算;第一个数据乘以六,其他数据与前一个数据比较,若较大差值乘6,否则差值乘4,最后加上次数乘5。

代码实现:

#include<stdio.h>
int main (void)
{
    int N,m,i,j;
    int a[110];
    while(scanf("%d",&N),N!=0)
    {
       for(i=0;i<N;i++)
           scanf("%d",&a[i]);
       m=a[0]*6;
       for(i=0;i<N-1;i++)
       {
          for(j=1;j<N;j++)
          {
               if(i==j-1)
               {
                   if(a[i]<a[j])
                      m+=(a[j]-a[i])*6;
                   else
                      m+=(a[i]-a[j])*4;
               }
          }
       }
       printf("%d\n",m+5*N);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值