贪心算法——Hdu 1050 Moving Tables

贪心算法训练(四)——(HDU1050)Moving Tables 贪心算法训练(四)——(HDU1050)Moving Tables 题目描述 在一个狭窄的走廊里将桌子从一个房间移动到另一个房间,走廊的宽度只能允许一个桌子通过。给出 t,表示有 t 组测试数据,再给出 n,表示要移动 n 个桌子。n 下面有 n 行,每行两个数字,表示将桌子从 a 房间移动到 b 房间。走廊的分布图如图所示,每移动一个桌子到达... 阅读详情

Moving Tables

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12304    Accepted Submission(s): 4226


Problem Description
The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure. 



The floor has 200 rooms each on the north side and south side along the corridor. Recently the Company made a plan to reform its system. The reform includes moving a lot of tables between rooms. Because the corridor is narrow and all the tables are big, only one table can pass through the corridor. Some plan is needed to make the moving efficient. The manager figured out the following plan: Moving a table from a room to another room can be done within 10 minutes. When moving a table from room i to room j, the part of the corridor between the front of room i and the front of room j is used. So, during each 10 minutes, several moving between two rooms not sharing the same part of the corridor will be done simultaneously. To make it clear the manager illustrated the possible cases and impossible cases of simultaneous moving. 



For each room, at most one table will be either moved in or moved out. Now, the manager seeks out a method to minimize the time to move all the tables. Your job is to write a program to solve the manager’s problem.
 

Input
The input consists of T test cases. The number of test cases ) (T is given in the first line of the input. Each test case begins with a line containing an integer N , 1<=N<=200 , that represents the number of tables to move. Each of the following N lines contains two positive integers s and t, representing that a table is to move from room number s to room number t (each room number appears at most once in the N lines). From the N+3-rd line, the remaining test cases are listed in the same manner as above.
 

Output
The output should contain the minimum time in minutes to complete the moving, one per line.
 

Sample Input
3 4 10 20 30 40 50 60 70 80 2 1 3 2 200 3 10 100 20 80 30 50
 

Sample Output
10 20 30

需要注意的是房间与走廊的位置关系,就如图中所给的图片所示


相对门的两个房间占用同一处走廊,所以例如有1——3和4——6移动方式时,它们是共享了同一段走廊的,即3号房间门前的走廊。

分析过程有如下图所示



代码一

#include <cstdio>
#include <algorithm>

using namespace std;

#define SIZE 205

struct Data_Type
{
	int from, to;
	bool flag;
}moving[SIZE];

bool Cmp(const Data_Type a, const Data_Type b)
{
	return a.from < b.from;
}

int main(void)
{
	int i, testNum, n;

	scanf("%d", &testNum);
	while (testNum-- != 0)
	{
		scanf("%d", &n);
		for (i = 0; i < n; i++)
		{
			scanf("%d%d", &moving[i].from, &moving[i].to);
			if (moving[i].from > moving[i].to)
			{
				int temp = moving[i].from;
				moving[i].from = moving[i].to;
				moving[i].to = temp;
			}
			if (moving[i].from % 2 == 0)
			{
				moving[i].from--;
			}
			if (moving[i].to % 2 == 1)
			{
				moving[i].to++;
			}
			moving[i].flag = false;
		}
		sort(moving, moving+n, Cmp);
		bool completion = false;
		int count = -1, priorTo;
		while (!completion)
		{
			completion = true;
			count++;
			priorTo = 0;
			for (i = 0; i < n; i++)
			{
				if (!moving[i].flag && moving[i].from > priorTo)
				{
					moving[i].flag = true;
					priorTo = moving[i].to;
					completion = false;
				}
			}
		}
		printf("%d\n", count*10);
	}
	return 0;
}

代码二


#include <stdio.h>
#include <string.h>

#define SIZE 405

int main(void)
{
	int count[SIZE];
	int i, j, testNum, n, max, from, to;

	scanf("%d", &testNum);
	while (testNum-- != 0)
	{
		scanf("%d", &n);
		memset(count, 0, sizeof(count));
		for (i = 0; i < n; i++)
		{
			scanf("%d %d", &from, &to);
			if (from > to)
			{
				int temp = from;
				from = to;
				to = temp;
			}
			if (from % 2 == 0)
			{
				count[from-1]++;
			}
			if (to % 2 == 1)
			{
				count[to+1]++;
			}
			for (j = from; j <= to; j++)
			{
				count[j]++;
			}
		}
		max = 0;
		for (i = 0; i < SIZE; i++)
		{
			if (count[i] > max)
			{
				max = count[i];
			}
		}
		printf("%d\n", max*10);
	}
	return 0;
}



moving Tables java 实现moving Tables 立即下载

相关推荐

手把手教你设计低噪声前置放大电路:从光电二极管到X射线探测器的实战配置

本文实战指南详细解析了低噪声前置放大电路的设计,重点针对光电二极管和X射线探测器等微弱信号源。文章深入对比了跨阻放大器与电荷灵敏放大器的核心架构、噪声优化策略及PCB布局技巧,手把手指导从电路选型、仿真验证到调试测试的全流程,助力工程师构建精准可靠的信号链。

tech5的博客 512

Moving Tables ——经典贪心和区间覆盖问题

The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure.      The floor has 200 rooms each on the north side and south side along th...

mumei的博客 893

一本集成电路静态时序设计经典之作(可下载)

本书全面深入探讨集成电路设计中关键技术的专著,涵盖了从基础知识到高级应用的各个方面。本书详细介绍了集成电路的发展历程、**静态时序分析的重要性、基本时序模型、时序信息库文件的构建、时序约束的设置、串扰噪声的影响及其控制方法**,并通过实战案例展示了如何进行有效的时序分析和优化。

nuoweishizi的博客 848

Moving Tables(贪心算法)

题目描述 著名的ACM公司租用了一幢楼的一层,其形状如下。 整个楼层在走廊的北面和南面各有300个房间。最近公司制定了一个改变布局的方案,包括在不同房间之间移动许多桌子。由于走廊狭窄,而且桌子都很大,只有一张桌子可以穿过走廊。为了提高工作效率,经理制定了如下方案:把一张桌子从一个房间搬到另一个房间可以在5分钟内完成。当移动一张桌子从I房间搬到J房间时,房间I前面和房间J前面的走廊部分被使用了。因此,在每5分钟,在不共用走廊的情况下,不同的移动方案可以同时进行。为了说明问题,经理举例说明了可能发生的情况和不可

weixin_47511190的博客 2095

沧小海深入剖析xilinx的GTP/GTX核,掌握高速串行收发机制——第六章 接收端结构及功能说明

总目录在这哦~ https://blog.youkuaiyun.com/z123canghai/article/details/107700878 第六章 接收端结构及功能说明 子目录 6.1 RX的模拟前端 6.2 RX的OOB信号 6.3 RX的均衡器 6.4 RX的CDR 时钟数据恢复 6.5 RX时钟输出结构 6.6 RX 的极性控制 6.7 RX 的PRBS 6.8 Rx字节、字的对齐功能 6.9 Rx接收弹性缓冲区 6.10 Rx的时钟纠正 6.11 Rx接收通道绑定 6...

滄海的博客 1万+

Android Audio常见问题分析方法

分析audio dump,确定写给BT的data是否正常,MTK平台Android原生架构分析threadloop write节点,高通平台分析QXDM 1586节点,从dump确定问题大概位置。分析systrace 确定性能。AudioFocus状态(用于播放或者音量异常的情况)。AudioTrack是否正常创建bt连接是否正常通路异常,setMode,setSpeakerphoneOn等都会影响设备选择,sco调用流程是否正常。

一条老狗的博客 2387

HDOJ_1050 Moving Tables 解题报告

Problem Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure.  The floor has 200 rooms each on the north sid

xxm137164869的专栏 2024

【YOLOs-CPP-图像分类部署】04-项目优化(加速部署)

本文详细介绍了将YOLO图像分类C++部署项目从CMake迁移到Visual Studio控制台应用的全过程。针对低配CPU性能瓶颈问题,作者通过替换多线程HPP代码为官方实现,并采用448x448固定输入尺寸优化推理速度。项目配置包含OpenCV和ONNX Runtime环境设置,实现了图像批量处理、分类结果显示及结果日志输出功能。关键步骤包括依赖库配置、DLL部署和代码调试,最终在Windows平台成功实现高效CPU推理。该方案显著提升了低配硬件的兼容性,为图像分类任务提供了稳定的部署解决方案。

深耕CV 353

Moving Tables贪心

题目:传送门 大概意思就是说:有一条走廊,两边各有两百个总共四百个房间(有编号的),任务是在这些房间之间移动桌子。当一张桌子从房间 s 移动到房间 t,那它们之间的走廊部分就被征用了,这部分的房间就不可以移动桌子,其他部分的房间可以移动桌子。移动一张桌子需要十分钟,求最短的移动桌子所花的时间。 思路:用数组mark标记走廊位置被标记的次数,若移动多个桌子时,所需要经过的走廊没有重合处,即可以同时移动。若有一段走廊有m个桌子都要经过,一次只能经过一个桌子,走过的走廊都要被标记一次,走廊被经过最多的次数乘以时间

G191018的博客 341

windows搭建IIS(FTP)

适用于参加网络系统管理的学生进行学习与参考

a1119619789的博客 280

S7-1200 PLC PID功能 | 调节PID参数

S7-1200 PLC PID功能 | 调节PID参数

Robot_PLC_HMI_Automation 1万+

HDU1050——Moving Tables(贪心)

The floor has 200 rooms each on the north side and south side along the corridor. Recently the Company made a plan to reform its system. The reform includes moving a lot of tables between rooms. Because the corridor is narrow and all the tables are big, on

WAR___NING的专栏 793

基于FPGA的以太网设计(1)----大白话解释什么是以太网

基于FPGA的千兆以太网设计(1)----大白话解释什么是以太网

孤独的单刀 3869

《贪心算法》— HDU 1050 Moving Tables

Moving Tables Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 36591Accepted Submission(s): 12038 Problem Description The famous...

69小石头的博客 488

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

Moving Tables hdu1050 贪心算法

http://acm.hdu.edu.cn/showproblem.php?pid=1050 写此题写的非常不淡定。。 以至于WA了很多很多很多很多次。。明明是很简单的。 唉。 注意两点:①房间是对称分布的 ②挪桌子的房间序号的不一定是按照升序或者降序排列的。 #include using namespace std; #define N 205 int room[N]; inline

operator456的专栏 831

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

hdu 1050 Moving Tables(贪心算法)

此题是一个与我的上篇文章 “东东的女朋友” 极为类似的算法的一道题,依然是贪心算法的应用,针对于此题,需要注意的是不可以同时移动的 情况(Impossible)的第3种,和可以移动(Possible)的情况的第二种(见下图): 下面代码及解释如下: View Code #include <stdio.h>#include <stdlib.h>...

177

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

HDU——1050 Moving Tables(贪心算法)

Problem Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure. The floor has 200 rooms each on the north side and so...

LightOn 353

hdu1050 Moving Tables 贪心算法 图理解 秒懂

可以叫做重叠法? 就是把所有经过的路径用数组记录下来,最后判断重叠最多的数组中的数 然后乘以时间。如同下图所示。emmm可能有点不清楚。直接上代码了! #include&lt;stdio.h&gt; #include&lt;string.h&gt; int main() { int t, m,s, temp,d, a[300]; int i, j; int min; scanf("%...

youtiankeng的博客 323

hdu 1050 Moving Tables(贪心算法)

Problem Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure. The floor has 200 rooms each on the north side and

KeepTing 511

Hdu1050 - Moving Tables - 贪心算法

#include #include using namespace std; struct Go//存储路线的起点房间和终点房间,以及是否使用过 { int st,ed; int move; }go[205]; int cmp(Go a,Go b)//将起点从小到大排起来 { return a.st<b.st;//这里不排终点,因为下面是计算最少有多少时间,也就是最少同时移动几次,而不是最多

New Star的acm 631

杭电 1150 moving tables

http://acm.hdu.edu.cn/showproblem.php?pid=1050 Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 18850    Accepted Submiss...

weixin_34067102的博客 101

HDU1050(Moving Tables:贪心算法)

解题思路: 这种做法是基于hdu2037的做法上考虑的,找出所有可以同时搬运的桌子,然后就很方便求出最短总时间。 还有一种更简单的做法是直接遍历一遍找出与别的重复次数最多的那片区域,重复次数*10就可以得到结果。 Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 6553...

weixin_30782293的博客 150

[ACM_HDU_1050]Moving Tables(贪心算法)

Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 9950 Accepted Submission(s): 3389 Description The famous ACM (Advanced Compu

691
上一篇: 字典树——Hdu 1247 Hat’s Words
下一篇: 补码的代数解释
庞老板
博客等级 码龄15年 127粉丝 66原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

庞老板

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值