杭电HDUACM1008

Elevator

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


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
 
题目描述翻译:我们城市最高的建筑物只有一个电梯。一个请求列表是由N个正数组成的。在指定的顺序中,数字表示电梯将停在哪个楼层。将电梯向上移动一层需要6秒,向下一层移动4秒。电梯将在每一指定站停留5秒钟。
对于给定的请求列表,您需要计算用于满足列表上请求的总时间。电梯开始时在第0层,当要求完成时,不需要返回地面。
个人理解:一开始把input那里看成要输入四个层数,对着output的数据算了半天都不对,可能是语文不好吧。实际上,input的每一行开头的数字是总共要移动的层数,后面是对应的指定层数,往上走6秒,往下走4秒,指定站停五秒。
                  我用的数组来存储指定层,然后通过循环来逐个比对,来决定是上升还是下降,不过循环里面的循环次数设定有点麻烦,可能是不太熟吧,回头把循环重新看一遍。
#include<iostream>
using namespace std;
int main()
{
    int n;
    while(cin>>n)
    {
        if(!n) break;
        int time,i,j,a[1000]={0},start=0;
        for(i=0;i<n;i++)
        {
            cin>>j;
            a[i]=j;
        }
        time=a[0]*6+5;
        for(i=0;i<n-1;i++)
        {
           if(a[i]<=a[i+1])
                time=time+(a[i+1]-a[i])*6+5;
           else
                time=time+(a[i]-a[i+1])*4+5;
        }
        cout<<time<<endl;
    }
}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值