hdu 1372 Knight Moves(广搜)

搜索--poj3984 迷宫问题(广搜C+深搜C++)+HDU 1372 Knight Moves 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, };它表示一个迷宫,其中的1表示墙壁,0表示可以走的路,只能横着走或竖着走,不能斜着走,要求编程序找出从左上角到右下角的最短路线。 Input 一个5 × 5的二维数组,... 阅读详情

 

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


Problem 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 file 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.

Source

Recommend
Eddy
 
典型的广搜题目,复习时写点,感觉有点生疏了,不过还行,一次过了。
代码:
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;

const int tx[]={1,-1,2,-2,1,-1,2,-2};
const int ty[]={2,2,1,1,-2,-2,-1,-1};
class A
{
  public:
  int x,y,step;
};

A map[100000];
bool vis[15][15];
int x_start,y_start,x_end,y_end;
int ans;
int bfs()
{
  if(x_start==x_end&&y_start==y_end)
  return 0;
  ans=0;
  int front=0,rear=1;
  int dx,dy;
    dx=x_start;
    dy=y_start;
    map[0].x=x_start;
    map[0].y=y_start;
    map[0].step=1;
    vis[dx][dy]=1;
  while(front<rear)
  {
    for(int i=0;i<8;i++)
    {
      dx=map[front].x+tx[i];
      dy=map[front].y+ty[i];
      if(dx>8||dx<1||dy>8||dy<1||vis[dx][dy])
      continue;
      if(dx==x_end&&dy==y_end)
      return map[front].step;
      map[rear].x=dx;map[rear].y=dy;
      map[rear].step=map[front].step+1;
      rear++;
    }
    front++;
  }
  return 0;
}

int main()
{
  //freopen("4.txt","r",stdin);
  char start,end;
  while(scanf("%c%d %c%d",&start,&y_start,&end,&y_end)!=EOF)
  {
    getchar();
    x_start=start-'a'+1;
    x_end=end-'a'+1;
    memset(vis,0,sizeof(vis));
    int z=bfs();
    printf("To get from %c%d to %c%d takes %d knight moves.\n",start,y_start,end,y_end,z);
  }
}

FDTD远场分析实战:从monitor数据到3D远场可视化的完整流程 本文详细介绍了FDTD远场分析的完整流程,从monitor采集的近场数据出发,通过近场-远场变换(NFFFT)生成3D远场可视化结果。文章重点解析了远场转换的物理原理、关键参数设置,并提供了构建稳健数据处理流水线及高级可视化(如3D辐射方向图)的实战脚本与技巧,适用于天线设计与光学器件分析。 阅读详情

相关推荐

LangGraph的容错机制:从节点失败到图级回滚

核心概念铺垫:讲解LLM应用容错与事务性的核心概念(幂等性、重试策略、降级策略、快照、回滚、原子性、一致性、隔离性、持久性、最终一致性),对比LangGraph容错机制与传统数据库ACID事务、Apache Airflow/Kubernetes Workflow/Kubeflow Pipelines容错机制的异同;LangGraph容错机制的演进历史:用markdown表格梳理LangGraph从0.0.1到1.5.0(截止202X年X月)的容错机制发展历程;节点级别的容错:重试与降级。

AI Python 编程之道的博客 172

HDU 1372 Knight Moves【广搜】

题目链接 题目意思类似于中国象棋中的马走日,就是给一个7*7的棋盘,现在给你两个点,让你计算从一个点到另一个点按照马走日的走法,需要走几步。解题思路就是一个简单的广搜,注意搜的方向是按照日字型来搜的,其他的和普通的广搜也没有区别。代码部分#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> #i

长颜草的博客 261

ArcMap 10.7/10.8启动加载界面后闪退?可能是这个隐藏的Normal.mxt模板文件在搞鬼

本文深入分析了ArcMap 10.7/10.8启动加载界面后闪退的问题,指出Normal.mxt模板文件损坏是常见原因。提供了从定位、删除模板文件到系统级修复的完整解决方案,帮助GIS工程师快速恢复工作流程。

weixin_28523493的博客 330

HDU 1372 Knight Moves(广搜BFS)

Knight Moves Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 10685    Accepted Submission(s): 6276 Problem Description A friend o

香橙的博客 378

python数据分析与可视化

Python数据分析主要包括数据清洗、数据探索和数据可视化三个部分。数据清洗是数据分析的重要环节,主要是对数据进行预处理,包括缺失值处理、异常值处理、数据类型转换等。数据探索则是通过对数据进行初步分析,了解数据的分布和特征,为后续的数据分析提供基础。数据可视化则是将数据以图形化的方式呈现,帮助人们更好地理解和分析数据。

2301_82032652的博客 7712

advanced installer 打包Flutter的Windows程序安装包(基本打包、开机自启、定时自动检测升级、包含卸载程序)

advanced installer 打包Flutter的Windows程序安装包(基本打包、开机自启、定时自动检测升级、包含卸载程序)

qq_45634989的博客 2878

HDU 1372 Knight Moves (广搜)

题目链接 Problem 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...

weixin_30518397的博客 168

手把手教你用MaxEnt+ArcGIS玩转物种分布预测

本文详细介绍了如何利用MaxEnt最大熵模型与ArcGIS软件进行物种分布预测。通过实战案例,从数据收集、环境变量处理、模型参数设置到结果可视化分析,手把手教你掌握生态位模型的核心流程。结合SDM toolbox插件,可高效完成数据预处理与高级空间分析,是生态学与保护生物学研究的实用指南。

weixin_29309475的博客 559

HDU 1372---- Knight Moves (广搜)

在国际象棋中Knight称“马”或“骑士”,Knight的走法和中国象棋中马相同, 同样是走“日”字,或英文字母大写的“L”形 另外此题充分利用队列!!! Description Background Mr Somurolov, fabulous chess-gamer indeed, asserts that no one else but him can mo

就是乐 389

驱动兼容_FANUC 驱动器兼容问题探讨

近10年来,FANUC伺服驱动器随着系统的升级而升级,不同的系统,可以兼容很多种类的驱动器,作者做了一些常见经验总结如下表:电源模块伺服放大器主轴放大器bi一体18i/OIB/OIC6110-Hxxx6114-Hxxx6111-Hxxx6134-Hxxx31iA/OID6140-Hxxx6117-Hxxx6141-Hxxx6164-Hxxx31IB/35IB/OIF/OI MATE D(5包)62...

weixin_34420941的博客 1751

网络发生环路了,别慌,这些步骤一定要安排起来!

网络环路是指在计算机网络中,数据包因为某种原因在多个网络设备之间不断循环,形成了一个闭环。这样数据包就永远也无法到达目标,导致网络的流量滞留,设备间的资源耗尽,最终网络性能受到严重影响。网络环路虽然是常见的网络故障,但只要掌握正确的排查和解决方法,面对环路问题时,你就能冷静应对,迅速恢复网络的正常运行。希望这篇文章能帮助你更好地理解和处理网络环路的问题,让你的网络环境更加稳定可靠!🚀📡如果你有任何疑问,或者在实际操作中遇到困难,随时可以联系我,我们一起攻克技术难题!

网络技术联盟站 1965

HDU1372 Knight Moves(广搜BFS+深搜DFS)

题目: Knight Moves Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 10658    Accepted Submission(s): 6264 Problem Description A f

riba2534的博客 719

【实战项目开发技术分享】ROS1.0、ROS 2.0和CyberRT开源通信框架对比

随着机器人和自动驾驶技术的飞速发展,开源通信框架在机器人、自动驾驶行业扮演着重要的角色。ROS1.0是一个广泛应用于机器人领域的开源框架,ROS 2.0是其改进版本,而CyberRT是Baidu Apollo自动驾驶平台的通信框架。ROS和ROS 2.0都注重灵活性和共享性,适用于各种机器人应用。CyberRT则专注于实时性和高性能,适用于自动驾驶等对实时性要求较高的场景。选择适合的框架取决于具体应用需求和开发者的偏好。

xiewf的博客 2万+

zoj 1091(pku2243,hdu1372) Knight Moves(广搜)

啥叫蛋疼……为啥蛋疼……我WA了一晚上,就因为……其实到现在我也不知道因为啥……之前一直错,在main开始run的时候,坐标录入我用的是scanf("%1s%d%1s%d",&ch1,&sj,&ch2,&dj)错的死去活来……后来在小媛的指点下,改成scanf("%c%d %c%d",&ch1,&sj,&ch2,&dj)就过了,所以小媛你欠我一个解释……代码在下面,传统bfs,老套路……#include #include #include #include using namespace std;

laoda扯一扯 1009

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

HDU--杭电--1372--Knight Moves--广搜--就是象棋里面‘马’走日一样走,水题

Knight Moves Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4999    Accepted Submission(s): 3057 Problem Description A friend of you

浩爷地带,你的地盘听我的.... 1533

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

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

hdu 1372 Knight Moves

hdu   1372   Knight Moves              题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1372                                                               题目大意:同样还是跑马数步数(不过千万别以为是和poj1915一样的题啊~) 题目分

slicer的技术交流栈 927

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

HDU - 1372 Knight Moves(bfs入门)

HDU - 1372 Knight Moves 题目链接:https://vjudge.net/problem/HDU-1372#author=swust20141567 题目: 在象棋王国,尼古拉斯.火山是一匹英俊的马,他非常幸运迎娶了白马王国的公主,他们将度蜜月,你现在是他们的女仆,火山会问你去一些地方最少需要多少步,这么简单的事当然难不倒你。由于火山是一匹马,他的移动方式将会遵...

weixin_30294709的博客 94

HDOJ 1372 Knight Moves(BFS 广搜)

题目: Knight Moves Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3684    Accepted Submission(s): 2293 Problem Description A friend o

ferry9303的专栏 1164

HDU1372&POJ2243Knight Moves(BFS呀,转换一下)

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

AC_Dreameng 1040

HDU 1372 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 of n squares on a chessboa...

Gem 2003

杭电 1372 Knight Moves(广搜模板题)

http://acm.hdu.edu.cn/showproblem.php?pid=1372 Knight Moves Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6439    Accepted Submission(s)

u012766950的专栏 1294

HDU-1372 Knight Moves

HDU 1372 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 of n...

你呢的博客 935

hdu 1372 Knight Moves

hdu 1372  Knight Moves Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64d Description A friend of you is doing research on the Traveling Knight Problem (TKP)

GrEedWish_X的专栏 512

HDU1372:Knight Moves(BFS)

Problem 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

ACM!荣耀之路! 9260
上一篇: hdu 1035 Robot Motion
下一篇: hdu 2082 找单词(母函数)
剑不飞
博客等级 码龄15年 86粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值