博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
河南省第十届省赛 Intelligent Parking Building
阅读量:4908 次
发布时间:2019-06-11

本文共 4156 字,大约阅读时间需要 13 分钟。

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.

 样例输入:

31  51  -1  -1  -1  2 1  52  -1  -1  -1  1 3 6-1  5  6  -1  -1  3-1  -1  7  -1  2  9-1  10  4  1  8  -1

样例输出:

510320

分析:

表示英语不好的人伤不起,题意都是读了好久才读出来的,心累~~~~

OK,言归正传:

有一个地下车库,车库的高度为h,每层的车库中都有L个停车位,这L个停车位相当于是一个环形的传送带,传送带上有L个位置,每个位置上都可以停一辆车(相当于L个停车位)。有二维数组来表示当前楼层某个停车位上的停车信息,为-1的话意味着这个车位是空的,其余的数字依次表示车主提车的先后顺序(注意提车的时候肯定只能一辆一辆的提)。

让求得就是最后一位车主需要多久的时间才能够提到车,电梯上或者下一层所需10个单位时间,传送带转动一个车位需要5个单位时间,当然传送带可以正转也可以逆转。

首先肯定的是只能够一辆车一辆车的提,不能够在提一辆车的过程中顺便把下一辆车也提出去,这是不符合实际情况也不符合题意。然后就是关于传送带的位置问题(这里所说的位置都是传送带在楼梯口的那个位置,最开始的时候每一层都是一号位置),原先我就一直以为的是传送带在把车送到楼梯口后,就又回到原来的位置了,然后才意识到自己考虑的多了,传送带在把一辆车送到电梯口之后,传送带就不再动了,当前位置就是下一次的传送带的位置。

代码:

#include
#include
#include
#include
#include
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;}

转载于:https://www.cnblogs.com/cmmdc/p/6887779.html

你可能感兴趣的文章
PLSQL
查看>>
ASP.NET Core 应用程序Startup类介绍
查看>>
【python】-类的继承
查看>>
同一个POD中默认共享哪些名称空间
查看>>
HTTP协议详解
查看>>
xdebug调试的原理
查看>>
php 日期时间运算比较
查看>>
C#类、接口、虚方法和抽象方法
查看>>
Linq C#增删改查
查看>>
[转]第一章 Windows Shell是什么 【来源:http://blog.csdn.net/wangqiulin123456/article/details/7987862】...
查看>>
iOS获取设备UUID和IDFA
查看>>
模糊查询
查看>>
linux 出现:-bash-3.2$提示符
查看>>
jsp电子商务 购物车实现之二 登录和分页篇
查看>>
科普:搜索引擎的基本工作原理
查看>>
Docker Compose 原理
查看>>
mongodb index 的background 及集群的索引建立
查看>>
判断两个控件在同一个Window上是否有重叠
查看>>
Android+Jquery Mobile学习系列(3)-创建Android项目
查看>>
android:inputType参数类型说明
查看>>