问题 H: Intelligent Parking Building

来源:互联网 发布:mac做铃声 编辑:程序博客网 时间:2024/06/05 06:26
时间限制: 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



题目大意为:你要运车-1位空,你要按顺序1运到最后一辆,矩形表示一个楼层,上下楼要十秒,每层楼的放车是一个圆环可以顺逆时针转动,每次转动时5秒,问你全部车运出去最短要多久(一个小坑转动后是不会变回原来位置的)。


下面是这题的代码:

#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;int T,h,l,sum,i,j;struct node{    int floor;    //标记楼层    int num;        //标记车位号}car[2510];int main(){    int a[55][55];        cin>>T;    while(T--)    {        sum=0;        int maxx=0;        scanf("%d%d",&h,&l);        for(i=1; i<=h; i++)   //地图        {            a[i][0]=1;            for(j=1; j<=l; j++)            {                scanf("%d",&a[i][j]);                if(a[i][j]!=-1)                {                    car[a[i][j]].floor=i;                    car[a[i][j]].num=j;                    if(maxx<a[i][j])      //寻找要出的车辆数                        maxx=a[i][j];                }            }        }        for(i=1; i<=maxx; i++)            {            int floor=car[i].floor;            int num=car[i].num;            sum+=(2*(floor-1)*10);        //来返上下楼花的时间            int one=abs(num-a[floor][0]);    //判断顺逆            int other=l-one;            int minn=one<other?one:other;            sum+=minn*5;          //计算转车位时间            a[floor][0]=num;     //标记头个车位的号码        }        printf("%d\n",sum);    }    return 0;}