POJ 2243 Knight Moves

液态神经网络系列(四) | 一条 PyTorch 从零搭建 LTC 细胞 本文详细介绍了如何从零开始用PyTorch实现Liquid Time-constant Networks(LTC)神经元模型。首先将LTC的核心微分方程拆解为输入电导、系统时间常数和数值积分器三个模块,然后逐步构建LTCCell类,包括物理参数初始化、突触参数设置和前向演化过程。文章还展示了如何封装LTCModel处理不规则时间序列,并通过正弦波抗干扰实验验证了LTC模型的优越性。最后讨论了数值稳定性、计算代价等实现细节,并预告了下一篇将探讨使用伴随灵敏度算法优化显存占用的方法。 阅读详情
Knight Moves
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 9346 Accepted: 5342

Description

A friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find the shortest closed tour of knight moves that visits each square of a given set of n squares on a chessboard exactly once. He thinks that the most difficult part of the problem is determining the smallest number of knight moves between two given squares and that, once you have accomplished this, finding the tour would be easy.
Of course you know that it is vice versa. So you offer him to write a program that solves the "difficult" part. 

Your job is to write a program that takes two squares a and b as input and then determines the number of knight moves on a shortest route from a to b.

Input

The input will contain one or more test cases. Each test case consists of one line containing two squares separated by one space. A square is a string consisting of a letter (a-h) representing the column and a digit (1-8) representing the row on the chessboard.

Output

For each test case, print one line saying "To get from xx to yy takes n knight moves.".

Sample Input

e2 e4
a1 b2
b2 c3
a1 h8
a1 h7
h8 a1
b1 c3
f6 f6

Sample Output

To get from e2 to e4 takes 2 knight moves.
To get from a1 to b2 takes 4 knight moves.
To get from b2 to c3 takes 2 knight moves.
To get from a1 to h8 takes 6 knight moves.
To get from a1 to h7 takes 5 knight moves.
To get from h8 to a1 takes 6 knight moves.
To get from b1 to c3 takes 1 knight moves.
To get from f6 to f6 takes 0 knight moves.

 

直接简单BFS就可以过得题,练习下双向BFS

 

#include<cstdio>
#include<cstring>

using namespace std;

typedef struct Node{
	int x,y;
	int cent;
}; 

Node queue[2][100];
int hash[2][10][10];

int BFS(Node &star,Node &end)
{
	int base[2],top[2];
	int flag=0,i,j,k,tmp;
	int cc[8][2]={1,2,   1,-2,   -1,2,   -1,-2,   2,1,   2,-1,   -2,1,   -2,-1};

	if(star.x==end.x && star.y==end.y)
		return 0;

	star.cent=0;	end.cent=0;
	base[0]=base[1]=top[0]=top[1]=0;


	queue[0][0]=star;
	queue[1][0]=end;

	memset(hash,-1,sizeof(hash));;

	hash[0][star.x][star.y]=0;	hash[1][end.x][end.y]=0;

	while(base[flag]<=top[flag] || base[tmp]<=top[tmp])
	{
		tmp=(flag+1)%2;
		if(base[flag]>top[flag])
		{
			flag=tmp;
			continue;
		}

		for(i=0;i<8;i++)
		{
			int tmp_x=queue[flag][base[flag]].x+cc[i][0];
			int tmp_y=queue[flag][base[flag]].y+cc[i][1];

			if(tmp_x>0 && tmp_x<=8 && tmp_y>0 && tmp_y<=8 && hash[flag][tmp_x][tmp_y]==-1)
			{
				if(hash[tmp][tmp_x][tmp_y]!=-1)
					return queue[flag][base[flag]].cent+hash[tmp][tmp_x][tmp_y]+1;
				queue[flag][++top[flag]].x=tmp_x;
				queue[flag][top[flag]].y=tmp_y;
				queue[flag][top[flag]].cent=queue[flag][base[flag]].cent+1;
				hash[flag][tmp_x][tmp_y]=queue[flag][top[flag]].cent;
			}
		}

		base[flag]++;
		flag=tmp;
	}

}


int main()
{
	int A,B;
	char a,b;

	Node star,end;

	while(scanf("%c%d %c%d",&a,&A,&b,&B)==4)
	{
		star.x=a-'a'+1;	star.y=A;
		end.x=b-'a'+1;	end.y=B;

		printf("To get from %c%d to %c%d takes %d knight moves.\n",a,A,b,B,BFS(star,end));

		getchar();
	}

	return 0;
}


 

【绝对要收藏-优秀论文范文】高项-度量绩效域 摘要:本文基于某水库数字孪生平台建设项目(2022.9-2023.5,645.97万元)的管理实践,从信息系统度量绩效域角度展开论述。项目构建了包含防洪调度等6大子系统的数字平台,实现洪水"四预"功能。重点分析了度量绩效域的五大要点:制定有效指标(如成本±8%偏差阈值)、多维数据采集、预警临界值设定、基于趋势的主动干预和持续改进机制。特别阐述了绩效问题的诊断方法,包括设备采购全周期成本分析、阶段性成本报告制度等。项目状态展示采用三维可视化看板,集成进度、成本、质量等多维度实时数据,最终实 阅读详情

相关推荐

用4690张图片搞定物流仓储难题:手把手教你训练YOLOv8纸箱检测模型(附完整源码)

本文详细介绍了如何利用YOLOv8目标检测技术解决物流仓储中的纸箱识别难题。通过4690张图片构建高质量数据集,提供完整的训练教程和源码,实现98.7%的mAP@0.5准确率。文章涵盖数据采集、模型训练、调参技巧到边缘计算部署的全流程,帮助读者快速构建智能仓储检测系统。

weixin_28717939的博客 377

POJ - 2243 Knight Moves

https://vjudge.net/problem/POJ-2243 题目 A friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find the shortest closed tour of knight moves that visits each square of a given set of n squares on a chessboard exactly once.

斯文~ 352

自然语言处理:稀疏向量表示

稀疏向量表示是指运用特定的方法和技术,将数据(如文本、图像、信号等)转化为向量形式,且该向量具有大部分元素值为零,仅少数元素值非零的特征,以此来实现对数据的高效存储、处理和分析。

老赵爱学习的博客 1443

POJ2243 Knight Moves —— A*算法

题目链接:http://poj.org/problem?id=2243 Knight Moves Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14500   Accepted: 8108 Description A friend of yo

A man can be destroyed, but not defeated. 460

保姆级教程:在RV1126开发板上跑通YOLOv5口罩检测(从数据集到摄像头实时识别)

本文提供了一份详细的RV1126开发板部署YOLOv5口罩检测系统的全流程指南,涵盖数据集准备、模型训练优化、边缘部署及实时摄像头识别等关键步骤。重点解析了RV1126开发板的性能特征、YOLOv5模型训练调优技巧、RKNN模型转换量化策略,以及部署过程中的性能优化方案,帮助开发者高效实现边缘端目标检测应用。

weixin_27310985的博客 108

【linux】解决报错:Network error: Connection refused

【linux】解决报错:Network error: Connection refused

weixin_44502754的博客 4936

poj2243 Knight Moves

<br />#include<iostream><br /> #include<queue><br /> using namespace std;<br /> struct d_node{<br />  int a,b;<br /> };<br /> d_node d[8]={{-2,1},{-1,2},{1,2},{2,1},{2,-1},{1,-2},{-1,-2},{-2,-1}};<br /> int visited[8][8];<br /> struct state_node{<b

rightbag的专栏 878

【数字孪生与仿真技术】10:半导体制造中的虚拟量测技术深度解析:从多尺度建模到工业级应用

摘要:半导体制造过程中,晶圆加工需实时监测300+关键参数,传统物理量测技术面临产能损耗、延迟检测等痛点。本文系统阐述虚拟量测(Virtual Metrology)技术的完整解决方案,通过多尺度混合建模实现物理机理与数据驱动的深度融合。内容涵盖等离子体刻蚀、薄膜沉积等关键工艺的物理模型构建,LSTM神经网络的数据校正算法,以及边缘-云协同的实时部署架构。某12英寸晶圆厂实践表明,虚拟量测技术可减少70%物理量测频次,异常漏检率从18%降至3%,机台利用率提升11%。

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 2546

Knight Moves(POJ2243)

题目: A friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find the shortest closed tour of knight moves that visits each square of a given set of n squares on a ches...

qq_44859533的博客 483

qwen2vl ValueError: Image features and image tokens do not match: tokens: 568, features 600

本文介绍了一个用于计算多模态数据集中样本token数量的Python工具,特别针对包含文本和图像的Qwen2-VL模型数据集。

q742971636的博客 1012

在Simulink中实现基于深度强化学习的控制算法仿真建模

通过上述步骤,你可以在Simulink中实现基于深度强化学习的控制算法仿真建模。这种方法适用于许多复杂的控制问题,尤其是当传统控制方法难以找到有效解决方案时。随着经验的积累,你可以进一步探索不同的深度强化学习算法及其变种,以适应更广泛的应用场景。此外,还可以结合其他先进技术(如迁移学习、多智能体协作等),提升模型的表现能力。

amy_mhd的博客 414

POJ-2243 Knight Moves

POJ-2243 Knight Moves 题目链接:POJ-2243 题目大意:骑士移动 日字型移动 棋盘列数为字母 行数为数字 问从e2到e4最少需要几步 解题思路:标准BFS 代码块: #include<iostream> #include<queue> #include<cstring> #include<string> using na...

鱼头的水题之路 201

巧妙解决网页弹窗重复出现问题

本文探讨了网页弹窗关闭后刷新重现的问题及解决方案。通过分析原生JavaScript实现的弹窗代码存在的缺陷,提出了使用jQuery改进的方法。关键点包括:利用event.preventDefault()阻止默认行为避免刷新,采用jQuery的hide("slow")方法实现优雅的关闭动画,确保关闭状态持久化。改进后的方案既解决了弹窗重复出现的问题,又提升了用户体验,为网页弹窗交互提供了更优的实现方式。文中提供了完整的HTML、CSS和JavaScript代码示例,便于开发者直接应用。

2501_90323865的博客 180

【POJ 2243】Knight Moves

题 Description A friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find the shortest closed tour of knight moves that visits each square of a given set o...

dingguayi7025的博客 92

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

poj 2243 Knight Moves

Knight Moves Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11794   Accepted: 6646 Description A friend of you is doing research on the Traveling Knight P

Jinbao 675

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

POJ Knight Moves 2243 x

                  Knight Moves Time Limit:1000MS Memory Limit:65536K Total Submissions:13974 Accepted:7797 Description A friend of you is doing research on the...

anjian3128的专栏 84

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

POJ2243 Knight Moves

题目链接:http://poj.org/problem?id=2243 #include #include int knight[64][64]; void Floyed() { int i,j,k,x,y; for(i=0;i<64;++i) { for(j=0;j<64;++j) {//棋盘两格之间的相对位置 x=abs(i/8-j/8); y=

不可不戒 627

POJ 2243 Knight Moves bfs

A friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find the shortest closed tour of knight moves that visits each square of a given set of n squares on a chessbo...

起名好难呀! 168

POJ2243-Knight Moves

http://poj.org/problem?id=2243 最简单的bfs输出下路径 #include<stdio.h> #include<string.h> struct { int x,y,step; } queue[10000],e; bool mark[10][10]; int dir[8][2]= {2,1,1,2,-1,2,-2...

weixin_30726161的博客 127

POJ 2243 Knight Moves (bfs)

Knight Moves Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13925   Accepted: 7766 Description A friend of you is doing research on the Traveling Knight P

stferghfsssz的博客 327

poj2243 Knight Moves 骑士游历问题的纯数学方法!!!

http://poj.org/problem?id=2243   下面稍微翻译一下:   描述:给你一个8*8的棋盘,骑士的开始位置,结束位置,让你求得骑士从开始位置开始揍到结束位置需要最小的步数是多少?(注意,骑士走日字) 输入:输入包含多组数据,每一行都是一组开始位置和结束位置,位置由两个字符组成,一个是小写字母(a-h),一个是数字(1-8),起始位置结束位置由一个空格隔开.

ckcz123的专栏 2650

POJ-2243-Knight Moves

题目 Description A friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find the shortest closed tour of knight moves that visits each square of a given set of n squares on a chessboard exactly once. He thinks that the most

m0_56861113的博客 197
上一篇: 乾坤大挪移
下一篇: POJ 1745 Divisibility
Magic_____
博客等级 码龄14年 11粉丝 160原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值