POJ 2286 HDU 1667 ZOJ 2396 The Rotation Game IDA*迭代加深搜索

BALM2深度解析 | 港大MARS实验室如何用点簇革新激光BA? 本文深度解析了港大MARS实验室提出的BALM2方案如何通过点簇技术革新激光BA(Bundle Adjustment)处理。BALM2将点云数据聚合为点簇,显著提升计算效率,实测显示其计算耗时仅为传统方法的1/20。文章详细介绍了点簇的核心原理、二阶优化方法及与传统方法的性能对比,展示了其在激光SLAM领域的突破性应用。 阅读详情
The Rotation Game
Time Limit: 15000MS Memory Limit: 150000K
Total Submissions: 3819 Accepted: 1262

Description

The rotation game uses a # shaped board, which can hold 24 pieces of square blocks (see Fig.1). The blocks are marked with symbols 1, 2 and 3, with exactly 8 pieces of each kind.

Initially, the blocks are placed on the board randomly. Your task is to move the blocks so that the eight blocks placed in the center square have the same symbol marked. There is only one type of valid move, which is to rotate one of the four lines, each consisting of seven blocks. That is, six blocks in the line are moved towards the head by one block and the head block is moved to the end of the line. The eight possible moves are marked with capital letters A to H. Figure 1 illustrates two consecutive moves, move A and move C from some initial configuration.

Input

The input consists of no more than 30 test cases. Each test case has only one line that contains 24 numbers, which are the symbols of the blocks in the initial configuration. The rows of blocks are listed from top to bottom. For each row the blocks are listed from left to right. The numbers are separated by spaces. For example, the first test case in the sample input corresponds to the initial configuration in Fig.1. There are no blank lines between cases. There is a line containing a single `0' after the last test case that ends the input.

Output

For each test case, you must output two lines. The first line contains all the moves needed to reach the final configuration. Each move is a letter, ranging from `A' to `H', and there should not be any spaces between the letters in the line. If no moves are needed, output `No moves needed' instead. In the second line, you must output the symbol of the blocks in the center square after these moves. If there are several possible solutions, you must output the one that uses the least number of moves. If there is still more than one possible solution, you must output the solution that is smallest in dictionary order for the letters of the moves. There is no need to output blank lines between cases.

Sample Input

1 1 1 1 3 2 3 2 3 1 3 2 2 3 1 2 2 2 3 1 2 1 3 3
1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3
0

Sample Output

AC
2
DDHH
2

Source

 
IDA*入门
代码:
#include<cstdio>
#include<algorithm>
using namespace std;

int deep,s[25],b[]={5,4,7,6,1,0,3,2};
int p[9][7]=
{
	0,2,6,11,15,20,22,
	1,3,8,12,17,21,23,
	10,9,8,7,6,5,4,
	19,18,17,16,15,14,13,
	23,21,17,12,8,3,1,
	22,20,15,11,6,2,0,
	13,14,15,16,17,18,19,
	4,5,6,7,8,9,10,
	7,8,11,12,15,16,17
};
char path[105],t;
int ok(int *s)
{
	for(int i=0;i<7;i++)
		if(s[p[8][i]]!=s[6])
			return 0;
	return 1;
}
int cal()
{
	int i,j,a[4]={0};
	for(i=1;i<=3;i++)
	{
		a[i]+=s[6]==i;
		for(j=0;j<7;j++)
			a[i]+=s[p[8][j]]==i;
	}
	return 8-max(a[1],max(a[2],a[3]));
}
int dfs(int k)
{
	int i,j,h=cal();
	if(h==0)
		return 1;
	if(h+k>deep)
		return 0;
	for(i=0;i<8;i++)
	{
		t=s[p[i][0]];
		for(j=0;j<6;j++)
			s[p[i][j]]=s[p[i][(j+1)%8]];
		s[p[i][6]]=t;
		path[k]=i+'A';
		if(dfs(k+1))
			return 1;
		t=s[p[b[i]][0]];
		for(j=0;j<6;j++)
			s[p[b[i]][j]]=s[p[b[i]][(j+1)%8]];
		s[p[b[i]][6]]=t;
	}
	return 0;
}
int main()
{
	int i;
	while(scanf("%d",s),s[0])
	{
		for(i=1;i<24;i++)
			scanf("%d",&s[i]);
		if(ok(s))
		{
			printf("No moves needed\n%d\n",s[6]);
			continue;
		}
		deep=0;
		while(1)
		{
			if(dfs(0))
				break;
			deep++;
		}
		for(i=0;i<deep;i++)
			putchar(path[i]);
		printf("\n%d\n",s[6]);
	}
}

 
STM32 A/B分区OTA升级实战:从原理到避坑指南 本文详细解析STM32 A/B分区OTA升级的核心原理与实战实现,涵盖双分区设计、Bootloader开发、固件传输验证及常见问题解决方案。重点介绍通过A/B分区实现无缝升级与安全回滚的机制,帮助开发者规避典型陷阱,提升嵌入式系统远程更新的可靠性与效率。 阅读详情

相关推荐

关于Arduino中的常用函数

一、I/O函数 二、时间函数 三、数学函数 abs 返回其参数的无符号值 【abs(12)返回12,abs(-12)也返回12】 constrain 限制一个数字以阻止它超出范围。第一个参数是被限制的数字,第二个参数是范围区间的开始,第三个参数是允许的数字范围区间的结尾。 【constrain(8,1,10)返回8,constrain(11,1,10)返回10,constrain(0,1,10)返回1】 map 将一个范围内的数字映射到另一个范围。第一个参数是要映射到数字,第二个和第三个参数是from范围(

TREE的博客 7334

IDA*学习笔记-HDU1667 The Rotation Game

以HDU1667为例,记录了IDA*的学习心得,终点提到A*构造的思路和原则

ex_voda的博客 292

西门子交换机环网冗余设置(实战篇2.2)

MRP的重组时间为 200ms 因此 PROFINET 通信必须选择大于 200ms 的看门狗时间,看门狗。ET200SP默认为 2ms*3=6ms) MRP 的重组时间为 200ms 故系统会报出看门狗超时。更新,默认是 3 个周期,超出设置的周期数就会报 IO 设备故障。时间不是直接配置的,而是作为没有 IO 数据可接受的更新周期,也就是允许几个周期没有数据。来达到大于 200ms 的看门狗时间的要求(看门狗时间 可接受更新周期数 更新时间)。是IO 控制器和 IO 设备)

weixin_42580591的博客 375

hdu 1667(IDA*)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1667 思路:大牛说是IDA*的入门题=.=构造h()=8-max(1,2,3);  max(1,2,3)表示中间的八个位置中出现最多的数的个数。 因为每次操作只能改变中间8个中的一个,所以可以这样构造启发式函数。 1 #include&lt;iostream&gt; 2 #inc...

weixin_34113237的博客 199

在Unity3d使用yolov8的onnx模型

输出OUTPUTS是float32[1,35,8400],表示它会输出一个大小为[1, 35, 8400]的浮点数张量。这个输出张量的维度表示了检测到的目标的数量、每个目标的预测参数以及网格单元的数量。输出张量的第一个维度1表示检测到的目标数量。每个目标由35个值组成,表示目标的类别、置信度、边界框的坐标及10个特定点的位置。要取得8400个数据中置信度最高的数据,然后获取该数据其他channel的数据。运行结果:(蓝色是检测手的边框,红点是自定义的点),其中的四个数字分别表示不同的维度。

shenqingyu0605202324的博客 5610

重磅!Repo Wiki!

RepoWiki是Qoder平台的智能文档生成功能,通过静态代码分析自动提取项目架构、模块依赖和核心逻辑,并持续追踪代码变更保持文档同步。其工作流程分为四个阶段:1)代码扫描与AST解析;2)结构分析与依赖映射;3)文档智能生成;4)增量更新机制。支持多种编程语言,能识别设计模式并推断技术决策,适用于新项目搭建和遗留系统维护。优势在于降低理解成本和提高开发效率,但存在文件数量限制和依赖Git的局限性。典型应用场景包括自动生成架构图、API手册和团队知识沉淀。

ayusong870的博客 4080

高精度计算2的n次幂

#include&lt;iostream&gt; #include&lt;cstring&gt; #include&lt;cstdio&gt; #include&lt;string&gt; #include&lt;vector&gt; #include&lt;cstdlib&gt; #include&lt;algorithm&gt; using namespace std; char a[1005

hxs的博客 2970

模型检测--工具KeYmaera

论文:KeYmaera: A Hybrid Theorem Prover for Hybrid Systems 作者:Andre Platzer and JanKeYmaera摘要1 介绍2用于混合系统的KeYmaera验证工具3混合系统,混合自动机和混合程序 摘要 KeYmaera是一种用于混合系统的混合验证工具,它结合了演绎,实数代数和计算机代数证明者技术。它是自然的自动和交互式定理证明器 混合系统的规范和验证逻辑。 KeYmaera支持差分动态逻辑,它是用于混合程序的实值一阶动态逻辑,是混合自动机的程

ziigea的博客 1079

hdu1667-IDA*-迭代加深搜索 A*算法

迭代加深搜索迭代加深搜索,实质上是限定下界的深度优先搜索。即首先允许深度优先搜索K层,若没有发现可行解,再将K+1后重复以上步骤搜索(即深度优先搜索k+1层),直到搜索到可行解。在迭代加深搜索的算法中,连续的深度优先搜索被引入,每一个深度约束逐次加1,直到搜索到目标为止。可以看出,很多情况会重复搜索。但是它的好处在于: 空间开销小。每个深度下实际上是一个有深度限制的深度优先搜索。而DFS的空间消耗小

WilliamSun0122的博客 5199

智能挂锁软件需求规格说明书(SRS)

智能挂锁系统SmartPadlockV1.0是一款融合蓝牙通信、指纹识别和远程控制技术的便携式安防设备。系统由设备端、移动App和云平台三部分组成,支持蓝牙配对(10米内)、指纹识别、OTP一次性密码等多种开锁方式,响应时间<1.5秒。产品采用SM2/SM4加密技术保障安全,日均20次使用下续航达180天,兼容iOS13+/Android8.0+系统。功能包括设备绑定、远程授权、开锁记录查询和OTA固件升级,符合个人信息保护法规要求,适用于仓储、快递柜等多场景应用。

moton2017的博客 2115

PyTorch深度学习实战(6)——神经网络性能优化技术

神经网络性能优化技术是指通过改进神经网络的结构、参数初始化、正则化和训练过程等方面来提高其性能和泛化能力的方法。优化技术的选择和调试需要根据具体问题进行,通过不断实验和调整,找到最适合网络的优化策略。本节首先训练了一个简单的全连接网络,然后在此基础上介绍了简单有效的神经网络性能提升技巧。

盼小辉丶的博客 1万+

HDU 1667 The Rotation Game IDA*搜索

转载请注明出处,谢谢 http://blog.csdn.net/ACM_cxlove?viewmode=contents           by---cxlove 第一个IDA*搜索。 迭代加深搜索是逐渐加深搜深度,和BFS比较,不需要大量内存存取状态,但是耗时增加,因为好多都是重复搜索。 因为迭代加深搜索适用于对内存要求高,但是对时限要求不太高的题目。 而IDA*就是在在迭代加深搜索中

窝不是爱酱,喵~~~~ 2223

华为OD机考双机位C卷 - AI处理器组合 (Java & Python & JS & GO & C++ & C)

> 2026华为OD机试双机位C卷 - 华为OD上机考试双机位C卷 华为OD机试双机位C卷真题目录点击查看: [【全网首发】2026华为OD机位C卷 机考真题题库含考点说明以及在线OJ(OD上机考试双机位C卷)](https://blog.csdn.net/banxia_frontend/article/details/155503868)

算法大师! 237

hdu1667 The Rotation Game(IDA*)

题意:#字形的图形,问将中间那一块转成相同数字需要的最少步数,输出字典序最小的路径。 分析:跟hdu2234的无题I比,相对简单一点。其实也只是估价函数好理解一点,其他都差不多,还是迭代深搜+A*,也就是IDA*。 估价函数h()=8-max(在要求的八个位置中,1,2,3,的个数); 很好理解,因为没转动一步,最多只能将一个位置改为正确的。所以当前状态下,剩余的最少步数=8-max(在要求...

weixin_30432007的博客 117

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

POJ 2286 The Rotation Game

第一次写IDA*。。。。 The Rotation Game Time Limit: 15000MS   Memory Limit: 150000K Total Submissions: 4915   Accepted: 1635 Description The rotation game uses a # shaped b

码代码的猿猿 1739

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

HDU1667:The Rotation Game(IDA星)

Problem Description The rotation game uses a # shaped board, which can hold 24 pieces of square blocks (see Fig.1). The blocks are marked with symbols 1, 2 and 3, with exactly 8 pieces of each kind. 

ACM!荣耀之路! 3008

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

hdu1667The Rotation Game 迭代深搜IDA*

题目链接:http://acm.hdu.edu.cn/data/images/1667-1.jpg 题目是这个棋盘里面摆放着8个1,8个2和8个3,每一步你可以沿着A、B、 C、D、E、F、G、H任意一个方向移动该字母所指的长块。移出边界的小块会从 另一端移进来。如最左边的棋盘经过操作A,就会变成中间的棋盘布局, 再进行操作C,就会变成右边的棋盘布局。 要使的最中间的8个格子的数字

AcmLzq的博客 750

HDU 1667 The Rotation Game(IDA*)

The Rotation Game#include &lt;iostream&gt; #include &lt;stdio.h&gt; #include &lt;string.h&gt; #include &lt;algorithm&gt; using namespace std; int map[10][10]; int _hash[8] = {3, 5, 3, 5, 5, 3, 5, 3};...

ccshijtgc的专栏 228

【搜索进阶】HDU 1667 The Rotation Game

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1667 IDA*的入门题目,状态过多容易超内存,正好体现了IDA*的优势,每次操作移动能使一个数字进入中间的八个位置,所以构造h()=8-max(1,2,3在中间8个位置的个数)

又见炊烟 562

hdu 1667 The Rotation Game(IDA*)

题目大意:         有一个井字形结构的图形,每条线上7个数字(1,2,3,),每次可以从八个方向将一条线上的数字循环移动1个距离,问经过最少几次什么操作,可以将图形中间的八个方块变成同一种数字。 解题思路:         使用IDA*进行搜索,估价函数为中间八个方块中,不是最多的数字的个数和。 注意点:         题目的输入和存储都不直观,需要十分细心。 代码: #i

accelerator_2016的博客 634

【POJ2286】The Rotation Game

Description The rotation game uses a # shaped board, which can hold 24 pieces of square blocks (see Fig.1). The blocks are marked with symbols 1, 2 and 3, with exactly 8 pieces of each kind.Initiall...

weixin_34356138的博客 225

hdu 1667 IDA*

第一道IDA*。。。。。。 给链接:点击打开链接 AC代码如下: #include #include #include #include using namespace std; int num[7][7]; int maxdeep; char record[1000]; bool check(){ int temp = num[2][2]; for( int i = 2;

马德里小铁匠的铁匠铺 772

HDU-1667 The Rotation Game(IDA*)

题意 https://www.luogu.org/problemnew/show/UVA1343 思路 首先枚举终态是 1,2,31,2,31,2,3 中的哪一个,然后再把 242424 个数字压成一个长度为 242424 的 010101 串(111 表示终态的数字),直接用 int\text{int}int 来表示这个数。 可以先打表出每一个操作,转动了哪些位置,然后就可以很快的挪动这个010...

Paulliant的博客 457

POJ 2286/HDU 1667 The Rotation Game 搜索-IDA*+迭代加深

题目地址:http://poj.org/problem?id=2286 本题若用广搜,空间需求量非常大,空间不足。深搜的话,深度很难控制,容易陷入死循环。在这个时候就要用到迭代加深的深搜方法。 所谓迭代加深,就是在深度无上限的情况下,先预估一个深度(尽量小)进行搜索,如果没有找到解,再逐步放大深度搜索。这种方法虽然会导致重复的遍历 某些结点,但是由于搜索的复杂度是呈指数级别增加

lamborghini1993 1690

HDU The Rotation Game

The Rotation Game Time Limit : 45000/15000ms (Java/Other)   Memory Limit : 150000/150000K (Java/Other) Total Submission(s) : 7   Accepted Submission(s) : 6 Problem Description The rotation game us...

weixin_33932129的博客 186

HDU 1667

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1667         据说是IDA*搜索入门题,以前老是不敢看IDA*,认为很复杂。其实也没想象中的那么难。看IDA*先对 迭代搜索有了解。然后看IDA*就简单多了。IDA*就是在迭代加深上添加了评估函数。。评估函数一般其实就是,当前状态预估到结束状态的最小步数。 下面是AC代码:#inclu

814
上一篇: HDU2821 Pusher HDU3500 Fling DFS搜索
下一篇: POJ3662 Telephone Lines 二分+最短路
power721
博客等级 码龄19年 176粉丝 135原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值