POJ 2243 Knight Moves bfs

大语言模型在构建UNSPSC 分类数据中的应用 UNSPSC 是联合国标准产品和服务代码。本文研究如何利用大语言模型生成分类系统的分析 阅读详情
  • 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.

/*题意描述:给出两个字符串用空格隔开,字符串中第一个元素为字母第二个为数字,字母是(ah)数字是(18)。按照马走日的格式来走,然后问第一个最短需要走多少步才能走到第二个哪里。

解题思路:用字符串的形式输入,把它分离开来,把字母转换成(1-8)的数字,然后把两个字符串转换成坐标。 */

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

int e[10][10],book[10][10];
int a,b,c,d;
int min;
char s[5],s1[5];

int next[8][2]={2,1, 1,2, -2,1, -1,2, 2,-1, 1,-2, -2,-1, -1,-2};
struct node
{
	int x,y,s;
}que[110];

void bfs(int x,int y)
{
	int head,tail,tx,ty;
	int k;
	head=1;
	tail=1;
	que[tail].x=x;
	que[tail].y=y;
	que[tail].s=0;
	book[a][b]=1;
	tail++;
	int flag=0;
	if(a==c&&b==d)
		printf("To get from %s to %s takes 0 knight moves.\n",s,s1);
	else
	{
		while(head<tail)
		{
			for(k=0;k<8;k++)
			{
				tx=que[head].x+next[k][0];
				ty=que[head].y+next[k][1];
				
				if(tx<1||ty<1||tx>8||ty>8)
					continue;
				if(book[tx][ty]==0)
				{
					book[tx][ty]=1;
					que[tail].x=tx;
					que[tail].y=ty;
					que[tail].s=que[head].s+1;
					tail++;
				}
				if(tx==c&&ty==d)
				{
					flag=1;
					break;
				}
			}
			if(flag==1)
			{
				printf("To get from %s to %s takes %d knight moves.\n",s,s1,que[tail-1].s);
				break;
			}
			head++;
		}	
	}	
 }
 
 int main(void) 
 {
 	while(scanf("%s%s",s,s1)!=EOF)
 	{
 		memset(book,0,sizeof(book));
 		min=99999999;
 		a=s[0]-'a'+1;
 		b=s[1]-'0';
 		c=s1[0]-'a'+1;
 		d=s1[1]-'0';
 		bfs(a,b);
	 }
	 return 0;
 }

Docker安装并运行AnythingLLM的详细教程 通过本文的介绍,你已经掌握了如何在 CentOS 系统上使用 Docker 安装并运行 AnythingLLM。AnythingLLM 提供了强大的功能,支持本地知识库搭建和多模态输入,非常适合个人和企业使用。希望本文能帮助你快速上手并搭建自己的 AI 知识库。 阅读详情

相关推荐

[记录一个bug]av_hwdevice_ctx_create出现Cannot allocate memory(附带库运行时路径)[已解决]

新写的程序里调用ffmpeg的av_hwdevice_ctx_create()这个函数,出现Cannot allocate memory。但是另个程序一样的代码,居然是成功的。 反复检查之后无果,就跳出去查了一下,看到一个问答: Have you tried to use ffmpg executables with the same libs that you using when you run the app? Have you tried to use ffmpg executables

熊猫Ben的博客 3585

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

Python实战:5分钟搞定抖音无水印视频下载(附完整代码)

本文系统介绍了抖音无水印视频下载的多种技术方案,重点解析了抖音视频的获取逻辑与去水印原理。文章提供了从零代码的浏览器插件到可编程的Python脚本的完整实现路径,并附带了详细的代码示例,帮助用户快速构建自己的抖音视频下载工具箱。

weixin_29089057的博客 846

POJ 2243 Knight Moves (BFS入门)

OJ题目:click here ~~ 题目分析:

649

用COMSOL计算复合材料板频散曲线:从建模到绘图全流程

导波在板结构中传播时,不同频率成分的速度不同,即频散现象。理解频散曲线是识别导波模态、确定相速度与群速度的基础,也是无损检测和结构健康监测中信号解读的关键。对于碳纤维增强复合材料等各向异性板,频散关系更加复杂,传统解析方法难以求解,数值仿真成为主流手段。通过COMSOL结合周期性边界条件与特征频率扫描,可以高效计算出复合材料板的频散曲线,进而绘制相速度和群速度随频率变化的图谱,为实验模态识别、换能器激励频率选择提供依据。本文以一个2毫米单向碳纤维板为例,详细介绍几何建模、材料参数设置、网格收敛验证、参数扫描

weixin_31412781的博客 233

BERT + BiLSTM-CRF 处理流程

BERT是一个基于 Transformer 的预训练语言模型。与传统的语言模型不同,BERT 是双向的,即它同时利用上下文信息进行词表示学习。BERT 在大规模语料库上进行预训练,可以捕捉到深层次的语言知识和上下文关系,生成非常丰富的词向量表示。在序列标注任务中,BERT 被用作输入文本的编码器,将每个词映射为上下文相关的词嵌入(embeddings)。

AI Agent 首席体验官 2256

poj 2243 Knight Moves bfs

水题,裸的bfs,基本没有要注意的 /* author:jxy lang:C/C++ university:China,Xidian University **If you need to reprint,please indicate the source** */ #include #include #include #include #include #define INF 1E

弱弱的jxy 592

C#:实现统计图像主颜色的算法(附完整源码)

C#:实现统计图像主颜色的算法(附完整源码)

希望我的博客,能帮上你解决学习中工作中所遇到的问题 519

POJ 2243 Knight Moves(BFS || 双向BFS)

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 g

nudt_oys的博客 399

OpenCV 实战篇——如何测算出任一副图片中的物体的实际尺寸?传感器尺寸与像元尺寸的关系?

本文介绍了通过相机图像测算物体实际尺寸的方法,重点分析了传感器参数与成像质量的关系。文章首先给出了物体实际尺寸的计算公式,涉及像素尺寸、距离、分辨率等参数。然后详细解析了传感器尺寸与像元尺寸的关系,指出相同分辨率下更大的传感器能获得更好的成像质量。此外还介绍了光学尺寸、像素尺寸对成像的影响,以及帧率的概念。最后提及了相机标定的重要性,并概述了从像素坐标系转换到世界坐标系的基本思路。这些知识为通过相机图像进行精确测量提供了理论基础。

程序员,他们想的是什么?他们想的永远都是技术,他们崇尚的也永远都是技术。 1335

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

POJ2243 Knight Moves(BFS)

题意: 输入两组坐标,输出骑士从一个到另一个最少要几步(骑士走日字) 要点: 标准的BFS题,寻找最短路径,用队列做 15170656 Seasonal 2243 Accepted 176K 16MS C++ 1099B 2016-02-17 17:36:15 #include #include #include #include us

SeasonJoe的博客 617

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

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

poj2243-Knight Moves-水bfs

#include#include #include #include using namespace std; #define INF 0x7f struct node{ int x, y; int cont; }; bool inq[8][8]; node cb[9][9]; char s1[3],s2[3]; int sx, sy, ex, ey, dx, dy; int

Candy糖醬的专栏 796

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

《搜索》— POJ 2243 Knight Moves(BFS)

Knight Moves Time Limit:1000MS Memory Limit:65536K Total Submissions:13959 Accepted:7790 Description A friend of you is doing research on the Traveling Knight Problem (TKP) w...

69小石头的博客 491

poj2243 Knight Moves(BFS)

题目链接 http://poj.org/problem?id=2243 题意 输入8*8国际象棋棋盘上的两颗棋子(a~h表示列,1~8表示行),求马从一颗棋子跳到另一颗棋子需要的最短路径。 思路 使用bfs求解,注意国际象棋中马的走法。 代码 1 #include <iostream> 2 #include <cstring> 3 #includ...

weixin_30455661的博客 98

POJ 2243 Knight Moves bfs || 双向bfs

题目:http://poj.org/problem?id=2243题意:给定一个8∗88*8的棋盘,编号为1−8和a−h1-8和a-h,按照给定的走法, 求从起点到终点需要的最少步数思路:直接bfsbfs或者双向bfs双向bfs都可以,在这题中,双向bfs双向bfs终于展现了比bfsbfs高的多的效率 bfs:bfs://700ms #include <iostream> #include <cs

弱智就要多努力 374

POJ 2243 Knight Moves(BFS或DFS)

POJ 2243 Knight Moves(BFS实现或DFS实现) http://poj.org/problem?id=2243 题意:一个8*8的中国象棋棋牌,给你两个坐标,问你马从起点走到终点最少需要几步.(马可以朝4个方向8种走法,只能走日字,具体见代码) 分析:首先用BFS实现. AC代码: 0ms #include #include #include using nam

code 1866

POJ 2243 Knight Moves(BFS)

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

wchhlbt的博客 812

[原]poj2243-Knight Moves-水bfs

#include<iostream>#include<cstdio> #include<cstring> #include<queue> using namespace std; #define INF 0x7f struct node{ int x, y; int cont; }; boo...

diejixiang8988的博客 115

POJ2243 Knight moves (BFS求最短路)

 Description A friend of you is doingresearch on the Traveling Knight Problem (TKP) where you are to find theshortest closed tour of knight moves that visits each square of a given set ofn s

ChenYitian 649

poj 2243 bfs Knight Moves

#include&lt;iostream&gt; #include&lt;cstring&gt; #include&lt;cstdio&gt; #include&lt;queue&gt; using namespace std; struct node { int x,y,step; }; node s,e; bool vis[10][10]; int d[8][2]={{1,2},...

jinvasshole 97

POJ 2243 Knight Moves(BFS)

POJ 2243 Knight Moves 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...

weixin_30556959的博客 150

【POJ】2243Knight Moves(BFS)

Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15703   Accepted: 8744 Description A friend of you is doing research on the Traveling Knight Problem (TKP) where you are t...

红点雷龙XL 202

POJ 2243:Knight Moves(双向BFS)

http://poj.org/problem?id=2243 问题概述:一个8*8的棋盘,给定一个起点(列a-h,行1-8)和一个终点(列a-h,行1-8),按骑士的走法(走日字),从起点到 终点的最少移动多少次 输入样例:                                 对应输出: e2 e4

加载中... 678

poj_2243/uva439 Knight Moves(bfs經典)

騎士遍歷問題,注意的是騎士

xyinktw的专栏 585

poj2243 Knight Moves (BFS)

题 意:给定国际象棋棋盘,要求马从某点跳到某点,求最少步数 思 路:即BFS求最短路径长度 学习点:BFS

The Slow Need To Start Eearly 556
上一篇: 单链表的创建、插入删除和查询
下一篇: POJ-2253 Frogger (Dijkstra)
鳳九~
博客等级 码龄8年 1384粉丝 215原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值