南邮 OJ 1557 Tower Parking

来源:互联网 发布:直通车助手软件 编辑:程序博客网 时间:2024/06/05 05:45

Tower Parking

时间限制(普通/Java) : 1000 MS/ 3000 MS          运行内存限制 : 65536 KByte
总提交 : 11            测试通过 : 6 

比赛描述

There is a new revolution in the parking lot business: the parking tower. The concept is

simple: you drive your car into the elevator at the entrance of the tower, 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 tower 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 tower 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

a conveyor belt one car in either direction takes 5 seconds.



输入

On the first line one positive number: the number of testcases, at most 100. After that per

testcase:

• 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 j th number on the ith line

describes the j th 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.


输出

Per testcase:

• One line with the number of seconds before the last customer is served.


样例输入

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

样例输出

25
320

提示

undefined

题目来源

NWERC 2007




//AC 0MS#include<iostream>#define N 50int x[N*N],y[N*N],c[N];int main(){//freopen("test.txt","r",stdin);int t,h,l,i,j,k,n,time;scanf("%d",&t);while(t--){n = time = 0;memset(c,0,sizeof(c));//WA1scanf("%d%d",&h,&l);for(i=0;i<h;i++){for(j=0;j<l;j++){scanf("%d",&k);if(k!=-1){x[k] = i;y[k] = j;if(n < k){n = k;}}}}for(k=1;k<=n;k++){j = y[k]-c[x[k]];//所在点减去这一层目前的中心if(j<0){j = -j;}if(j>l-j){j = l-j;}time += (x[k])*20 + j*5;c[x[k]] = y[k];}printf("%d\n",time);}}



0 0
原创粉丝点击