题目描述
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.
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.
•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
题目大意:有一个n层的环形停车场电梯在环的中心,车在传送带上,传送带可以转动(顺逆时针都可以),转动一次+5s,电梯可以上下楼层,一层+10s,-1代表没有车,数字代表取车的顺序1~?,求最少需要多长时间取完所有车。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int T,n,m,a[55][55],row[55];
struct point{
int x;
int y;
}p;
int judge(){
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
if(a[i][j]!=-1)
return 1;
return 0;
}
int main()
{
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
for(int i=0;i<=n;i++)
row[i]=1;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
scanf("%d",&a[i][j]);
int count=1,flag,sum=0;
while(judge()){
flag=1;
for(int i=1;i<=n&&flag;i++){
for(int j=1;j<=m&&flag;j++){
if(a[i][j]==count){
if(m-max(row[i],j)+min(row[i],j)>abs(j-row[i]))
sum=sum+(abs(j-row[i]))*5+(i-1)*20;
else
sum=sum+(m-max(row[i],j)+min(row[i],j))*5+(i-1)*20;
row[i]=j;
count++;
flag=0;
a[i][j]=-1;
}
}
}
}
printf("%d\n",sum);
}
return 0;
}