河南省第十届ACM省赛题目:问题 H: Intelligent Parking Building

来源:互联网 发布:ubuntu llmp 编辑:程序博客网 时间:2024/05/18 00:31


问题 H: Intelligent Parking Building

时间限制: 1 Sec  内存限制: 128 MB
提交: 26  解决: 19
[提交][状态][讨论版]

题目描述

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


题目翻译:

题目描述:
现在在停车生意上有一个新的革命,停车建筑,概念非常的简单,你把车开到建筑中电梯的入口,然后电梯和传送带会拖着车子到空位置停车,车就一直停在那里直到你来提车,当你回来的时候,电梯和传送带会把你的车运到出口。


这个建筑很简单,这里有一个中央电梯用来运送不同楼层的汽车,每一个楼都有一个传送带。这个传送带可以顺时针方向走也可以逆时针方向走(说明传送带是环形的),当电梯到达一层楼,传送带会旋转将车送到电梯。在最后一天,有许多车停放在建筑里,并且有许多人去提车,顾客按照先来先提车的原则(提车要按照车的编号从小到大提),电梯先移动到第一台车所在的层,传送带把车运上电梯,然后垫底下降,重复以上步骤。我们想知道在最后一位乘客提车需要等多长时间。电梯每移动一层需要10秒,传送带每移动一个位置需要5秒。


输入:
第一行有一个正整数,是测试数据的组数,最多有三十组测试数据,每组测试数据:
一个H,一个L,是停车塔的高度和传送带的长度。
H行L个数,代表每个车初始停放的位置。第I行的第J个数代表第
I层楼的第J个位置,数字-1代表一个位置是空的。R需要提R量车,电梯的入口在一楼,电梯原来在第一个位置,停车塔至少有一辆车。


输出:
求最后一个提车人等的时间。

好不容易把这个题纯翻译出来了,得知真相的我特别想去死,感觉快崩溃了,省赛竟然这个题目都做不出,感觉比赛的时候都翻译错了,很简单的模拟题目。


#include<iostream>#include<stdio.h>#include<string.h>#include<vector>using namespace std;int H,L;  ///停车塔的高度,和传送带的长度。struct pos{    int floor;    int dis;    int x;    int dir;}a[3000];vector<int>F[55];int vis[3000];int main(){    int t,x,temp;    scanf("%d",&t);    while(t--)    {        scanf("%d%d",&H,&L);        memset(vis,0,sizeof(vis));        memset(F,0,sizeof(F));        int mmax = -1;        for(int i = 1; i <= H; i++)            for(int j = 1; j <= L; j++)            {                scanf("%d",&temp);                if(temp != -1)                {                    F[i].push_back(temp); ///第i层停着好几辆车                    mmax = max(mmax,temp);                    a[temp].floor = i;                    a[temp].x = j;                    if(j-1 < L-j+1)     ///逆时针传送比顺时针快                    {                        a[temp].dis = j-1;                        a[temp].dir = -1;                    }                    else                    {                        a[temp].dis = L-j+1;                        a[temp].dir = 1;                    }                }            }        int ans = 0;        for(int i = 1; i <= mmax; i++)        {            ans = ans + a[i].dis*5+(a[i].floor-1)*10*2;            int j = a[i].floor;            vis[i] = 1;            for(int k = 0; k < F[j].size(); k++)            {                temp = F[j][k];                if(vis[temp]) continue;                if(a[i].dir == 1)                {                    a[temp].x = (a[temp].x+a[i].dis)%L;                    if(a[temp].x==0)                        a[temp].x = L;                }                else  ///逆时针转                {                    a[temp].x = (a[temp].x-a[i].dis+L)%L;                    if(a[temp].x == 0)                        a[temp].x = L;                }                if(a[temp].x-1 < L-a[temp].x+1)                {                    a[temp].dis = a[temp].x - 1;                    a[temp].dir = -1;                }                else                {                    a[temp].dis = L-a[temp].x+1;                    a[temp].dir = 1;                }            }        }        printf("%d\n",ans);    }    return 0;}


阅读全文
0 0
原创粉丝点击