POJ 3505 Tower Parking

来源:互联网 发布:ubuntu玩steam需要什么 编辑:程序博客网 时间:2024/06/06 00:56

原题地址
http://poj.org/problem?id=3505
Tower Parking
Time Limit: 1000MS Memory Limit: 65536K
  

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


注意:本来是水题,可是理解错了,那个传送带是每层都有,所以每一层的传送带的距离都不同,层间没有关系,所以需要使用个数组存储,而不是只使用一个临时变量。

冋.....................而不是像下图所示的

由于以前看到过这样的视频,所以主观臆断

下面就是视频地址惊恐








http://www.tudou.com/programs/view/TH--UuxKx_s/

下面是AC代码


/*************************************************************************** Problem: POJ 3505 Tower Parking* Copyright 2011 by Yan* DATE:* E-Mail: yming0221@gmail.com************************************************************************/#include <stdio.h>typedef struct pos{int x,y;}pos;pos position[2501];int turn[51];/*每一层的指向位置*//*n为循环数组的总长度,x和y分别是两个元素的位置[0--n-1]*求两个元素的最短距离*/int min(int n,int x,int y){return (x-y+n)%n<(y-x+n)%n?(x-y+n)%n:(y-x+n)%n;}int main(){int n;int h,l,tmp;int i,j;int cnt;int ans;int tmp_x,tmp_y;/*用于保存上次的指针位置*//*freopen("input","r",stdin);*/scanf("%d",&n);while(n--){scanf("%d %d",&h,&l);cnt=0;ans=0;/*Input*/for(i=0;i<h;i++){turn[i]=0;/*每层指针指向0位置*/for(j=0;j<l;j++){scanf("%d",&tmp);if(tmp!=-1){position[tmp-1].x=i;position[tmp-1].y=j;cnt++;}}}/*End of Input*/for(i=0;i<cnt;i++){/*printf("%d %d %d\n",i+1,position[i].x,position[i].y);*/ans+=20*position[i].x;ans+=5*min(l,position[i].y,turn[position[i].x]);turn[position[i].x]=position[i].y;}printf("%d\n",ans);}return 0;}



原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 华为麦芒4玩游戏卡怎么办 sim卡换卡通讯录丢了怎么办 换sim卡通讯录怎么办 麦芒4开不了机怎么办 麦芒5开不了机怎么办 麦芒6针丢了怎么办 麦芒6扬声器坏了怎么办 华为手机2s太卡怎么办 华为麦芒6网速慢怎么办 华为麦芒5太卡怎么办 小米note3拍照反应慢怎么办 华为刷机后还要账号密码怎么办 刷机后忘记华为账号和密码怎么办 荣耀7x耗电快怎么办 小米2s死机后怎么办? 电信合约卡不想用了怎么办 vivo合约机掉了怎么办 华为合约机丢了怎么办 两年合约机掉了怎么办 电信合约机丢了怎么办 s8合约机坏了怎么办 合约机的卡掉了怎么办 移动合约机屏幕碎了怎么办 5s用不了电信卡怎么办 vivo手机4g信号差怎么办 电信dns辅服务器未响应怎么办 笔记本wifi下载速度慢怎么办 苹果wifi下载速度慢怎么办 小米手机wifi下载速度慢怎么办 苹果8plus上网慢怎么办 小米5c死机了怎么办 苹果x自拍反方向怎么办 硅胶手机壳出油怎么办 指环扣松了怎么办图解 塑料放久了发粘怎么办 橡胶时间久了粘怎么办 胶的手机套变黄怎么办 手机壳硅胶变黄怎么办 硅胶手机壳大了怎么办 硅胶手机壳变大了怎么办 硅胶手机壳有点大怎么办