poj-3505 Tower Parking

Language:
Tower Parking
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 1490 Accepted: 932

Description

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.

Input

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 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.

Output

Per testcase:

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

Sample Input

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

Sample Output

25
320

Source

此题主要在于读明白题意,搞清楚具体是怎么停车的,要注意每一层都有传送带,且每一层传送带初始位置都在每层第一个位置,每次取车后,位置就变为相应要取得车所在层的所在位置,以便计算下一次取车的时候传送带要移动的距离,注意传送带上一层楼市时间是双向的,因为它还要下来,具体的看代码吧。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define min(a,b)(a<b?a:b)
void change(int a[]){
    int i;
    for(i=1;i<=60;i++)
       a[i]=1;
}

struct cars{
     int h;
     int l;
}car[2600];
int pos[60];
int main(){
    int i,j,T,H,L,num,temp,time,dis;
    scanf("%d",&T);
    while(T--){
        num=0,time=0;
        scanf("%d %d",&H,&L);
        for(i=1;i<=H;i++){
            for(j=1;j<=L;j++){
                scanf("%d",&temp);
                if(temp!=-1){
                   num++;
                   car[temp].h=i;
                   car[temp].l=j; 
                }                    
            }
        }
        change(pos);
        for(i=1;i<=num;i++){
            time=time+(car[i].h-1)*20;
            time=time+min(abs(car[i].l-pos[car[i].h]),L-abs(car[i].l-pos[car[i].h]))*5;
            pos[car[i].h]=car[i].l;
        }
        printf("%d\n",time);
    }
    system("pause");
    return 0;
}

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值