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.

样例输入:

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

分析:

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

OK,言归正传:

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

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

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

代码:

#include<stdio.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<iostream>
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;
}

最新文章

  1. jQuery 2.0.3 源码分析Sizzle引擎 - 词法解析
  2. JMeter学习-026-JMeter 分布式(远程)参数化测试实例
  3. a标签中href的触发
  4. fight
  5. Struts2实现简单的在线人数统计
  6. NET Office 组件Spire
  7. 学习记录:浏览器JAVASCRIPT里的WINDOWS,DOCUMNET
  8. xml 文件的增删改查
  9. Labview学习之远程控制VI
  10. 常用的模式、JSON与DTO
  11. android开发注意点
  12. iOS开发——发短信,邮件
  13. 进阶篇之纯css+字体实现五角星(半颗星)评分
  14. 数据访问(DAO)
  15. iOS中 百度地图详解 韩俊强的博文
  16. 解决logging模块日志信息重复问题
  17. spring+springmvc+ibatis整合注解方式实例
  18. sklearn中随机森林的参数
  19. 14 python读取文件时出现UnicodeDecodeError: &#39;gbk&#39; codec can&#39;t decode byte 0xb7 in position 26: illegal multibyte sequence解决方法
  20. 最小生成树之克鲁斯卡尔(kruskal)算法

热门文章

  1. EF使用报错说缺少引用
  2. C#文件重命名的代码
  3. Android2.2以上的版本HttpURLConnection.getContentLength()获取的size跟下载下来的file的legth不相等
  4. 免费天气预报API接口
  5. 【转】用ASP.NET Core 2.1 建立规范的 REST API -- 缓存和并发
  6. linux备忘录-正则表达式与文件格式化处理
  7. Linux SPI总线和设备驱动架构之四:SPI数据传输的队列化
  8. Internet History,Technology and Security
  9. Linux杂技
  10. 微信小程序小程序使用scroll-view不能使用下拉刷新的解决办法