第十届省赛-H-Intelligent Parking Building

问题 H: Intelligent Parking Building
时间限制: 1 Sec 内存限制: 128 MB
题目描述
There is a new revolution in the parking lot business: the parking building. The concept is simple: you drive your car into the elevator at the entrance of the building, and the elevator and conveyor belts drag the car to an empty parking spot, where the car remains until you pick it up. When you return, the elevator and conveyor belts move your car back to the entrance and you’re done.

The layout of the building is simple. There is one central elevator that transports the cars between the different floors. On each floor there is one giant circular conveyor belt on which the cars stand. This belt can move in clockwise and counterclockwise direction. When the elevator arrives on a floor, it becomes part of the belt so that cars can move through it.

At the end of the day the building is usually packed with cars and a lot of people come to pick them up. Customers are processed in a first come first serve order: the elevator is moved to the floor of the first car, the conveyor belt moves the car on the elevator, the elevator is moved down again, and so on. We like to know how long it takes before the last customer gets his car. Moving the elevator one floor up- or downwards takes 10 seconds and moving the conveyor belt one position in either direction takes 5 seconds.

输入
On the first line one positive number: the number of testcases, at most 30. Each test case specifies:

One line with two integers h and l with 1 ≤ h ≤ 50 and 2 ≤ l ≤ 50: the height of the parking tower and the length of the conveyor belts.
h lines with l integers: the initial placement of the cars. The jth number on the ith line describes the jth position on the ith floor. This number is −1 if the position is empty, and r if the position is occupied by the rth car to pick up. The positive numbers form a consecutive sequence from 1 to the number of cars. The entrance is on the first floor and the elevator (which is initially empty) is in the first position. There is at least one car in the parking tower.
输出
For each test case generate a single line containing a single integer that is the number of seconds before the last customer is served.

样例输入

3
1  5
1  -1  -1  -1  2 
1  5
2  -1  -1  -1  1 
3 6
-1  5  6  -1  -1  3
-1  -1  7  -1  2  9
-1  10  4  1  8  -1

样例输出

5
10
320

分析:
有一个地下车库,车库的高度为h,每层的车库中都有L个停车位,这L个停车位相当于是一个环形的传送带,传送带上有L个位置,每个位置上都可以停一辆车(相当于L个停车位)。有二维数组来表示当前楼层某个停车位上的停车信息,为-1的话意味着这个车位是空的,其余的数字依次表示车主提车的先后顺序(注意提车的时候肯定只能一辆一辆的提)。

让求得就是最后一位车主需要多久的时间才能够提到车,电梯上或者下一层所需10个单位时间,传送带转动一个车位需要5个单位时间,当然传送带可以正转也可以逆转。

首先肯定的是只能够一辆车一辆车的提,不能够在提一辆车的过程中顺便把下一辆车也提出去,这是不符合实际情况也不符合题意。然后就是关于传送带的位置问题(这里所说的位置都是传送带在楼梯口的那个位置,最开始的时候每一层都是一号位置),原先我就一直以为的是传送带在把车送到楼梯口后,就又回到原来的位置了,然后才意识到自己考虑的多了,传送带在把一辆车送到电梯口之后,传送带就不再动了,当前位置就是下一次的传送带的位置。
代码:

#include<bits/stdc++.h>
using namespace std;
struct node
{
    int floor;//楼层
    int num;//位置
}q[2510];
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int h,n,Max=-1;
        memset(q,NULL,sizeof(node));
        scanf("%d %d",&h,&n);
        int a[55][55];
        for(int i=1;i<=h;i++)
        {
            a[i][0]=1;//初始每一层的电梯口
            for(int j=1;j<=n;j++)
            {
                scanf("%d",&a[i][j]);
                if(a[i][j]!=-1)
                {
                    if(a[i][j]>Max)
                        Max=a[i][j];//记录有多少个车要取
                    q[a[i][j]].floor=i;//楼层赋值
                    q[a[i][j]].num=j;//位置赋值
                }
            }
        }
        int ans=0;
        for(int i=1;i<=Max;i++)
        {
            int nn=min(abs(q[i].num-a[q[i].floor][0]),n-abs(q[i].num-a[q[i].floor][0]));//计算传送带所要移动的位置数;
            //cout<<nn<<endl;
            ans+=nn*5+10*(q[i].floor-1)*2;
            a[q[i].floor][0]=q[i].num;//记忆传送带哪个位置停在电梯口;
        }
        cout<<ans<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值