title: Intelligent Parking Building 河南省第十届省赛
tags: [模拟,省赛]
题目描述:
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
分析:
表示英语不好的人伤不起,题意都是读了好久才读出来的,心累~~~~
OK,言归正传:
有一个地下车库,车库的高度为h,每层的车库中都有L个停车位,这L个停车位相当于是一个环形的传送带,传送带上有L个位置,每个位置上都可以停一辆车(相当于L个停车位)。有二维数组来表示当前楼层某个停车位上的停车信息,为-1的话意味着这个车位是空的,其余的数字依次表示车主提车的先后顺序(注意提车的时候肯定只能一辆一辆的提)。
让求得就是最后一位车主需要多久的时间才能够提到车,电梯上或者下一层所需10个单位时间,传送带转动一个车位需要5个单位时间,当然传送带可以正转也可以逆转。
首先肯定的是只能够一辆车一辆车的提,不能够在提一辆车的过程中顺便把下一辆车也提出去,这是不符合实际情况也不符合题意。然后就是关于传送带的位置问题(这里所说的位置都是传送带在楼梯口的那个位置,最开始的时候每一层都是一号位置),原先我就一直以为的是传送带在把车送到楼梯口后,就又回到原来的位置了,然后才意识到自己考虑的多了,传送带在把一辆车送到电梯口之后,传送带就不再动了,当前位置就是下一次的传送带的位置。
代码:
#include<stdio.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
struct Node
{
int floor;///楼层
int num;///停车位
} node[2509];
int main()
{
int T,n,m,Max;
scanf("%d",&T);
while(T--)
{
Max=-1;
memset(node,NULL,sizeof(node));///结构体整体初始化
int Tu[52][52];
scanf("%d%d",&n,&m);
for(int i=1; i<=n; i++)
{
Tu[i][0] = 1;///每一层最开始的时候传送带的位置都是1
for(int j=1; j<=m; j++)
{
scanf("%d",&Tu[i][j]);
if(Tu[i][j]!=-1)
{
if(Tu[i][j]>Max)///max表示的是最多有多少辆车需要提出去
Max=Tu[i][j];
node[Tu[i][j]].floor=i;///楼层赋值
node[Tu[i][j]].num=j;///停车位赋值
}
}
}
int sum=0,flag;
for(int i=1; i<=Max; i++)
{
sum+=(node[i].floor-1)*10*2;///每次提车的过程都相当于从一楼到停车楼层,在送回一楼,则电梯的时间加倍
int mm = min(abs(node[i].num - Tu[node[i].floor][0]),m- abs(node[i].num - Tu[node[i].floor][0]));
///在同行中,找距离左右两边最近的那个。
sum += mm * 5;
Tu[node[i].floor][0]=node[i].num;///传送带的位置有记忆功能
}
printf("%d\n",sum);
}
return 0;
}