H Intelligent Parking Building 河南第十届ACM真题 【模拟】

/*
有一个停车楼,停车楼里的车需要全部开出去,标号为-1的位置为空,其他的数字为汽车,汽车出库必须要按照数字从小到大的顺序,
停车楼出口为第一层第一个 位置,其中电梯在每一行的第一列, 每一行是一个环形传送带,每移动一格耗费5分钟,每移动一层消耗10分钟,
电梯每上楼接车,到达每一层接车,然后下去从开头出口出去。 问你最少耗费多长时间所有的车都可以出去。
*/

题意好难,思路不难。

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

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
int map[55][55];
struct Node{
	int x;
	int y;
}edge[50*52];
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		int i,j,h,l;
		int sum = 0;
		int count = 0;
		scanf("%d%d",&h,&l);
		for(i=1;i<=h;i++)
		{
			map[i][0] = 1;
			for(j=1;j<=l;j++)
			{
				scanf("%d",&map[i][j]);
				if(map[i][j] != -1)
				{
					edge[map[i][j]].x = i;
					edge[map[i][j]].y = j;
					if(map[i][j] > count){
						count = map[i][j];
					}
				}
			}
		}
		for(i=1;i<=count;i++)//汽车从小到大出库 
		{
			int x = edge[i].x;
			int y = edge[i].y;
			sum += ((x - 1)* 10 * 2);//电梯 上楼接 再回去从出口把车送出去  ,所以结果*2 
			int res = min(abs(y - map[x][0]),l - abs(y - map[x][0]));	//在同行中 找距离左右两边最近的那个。 
			sum += res * 5;
			map[x][0] = y;
		}
		printf("%d\n",sum);
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值