当前位置:网站首页>-Knight Parade-
-Knight Parade-
2022-08-10 01:47:00 【-JMY-】
Title description
The horse moves in Chinese chess according to the Japanese glyph rule, given a chessboard of n*m size, as well as the initial position (x, y) and target position (s, t) of the horse, it is required not to repeatedly pass the same one on the chessboardPoint, calculate how many steps the horse can take to reach the target position at least, and all chessboards ensure that there must be a path from the initial position to the end position.
Enter
The test data contains one row, which is six integers, which are the size of the chessboard and the initial position coordinate nmxyst.(1≤x, s≤n≤5, 1≤y, t≤m≤5)
Output
Contains one line, an integer that represents the minimum number of steps the horse can take to reach the target position.
Sample input
3 3 1 1 1 3
Sample output
2
Reference code:
#include
using namespace std;
int n,m;
int q[5000][2],x,y,s,t,hh,tt,kx,ky,l,gx,gy;
int dx[]={1,1,-1,-1,2,2,-2,-2};
int dy[]={2,-2,2,-2,1,-1,1,-1};
int d[50][50];
void bfs(){
while(hh!=tt){
kx=q[hh][1];
ky=q[hh][0];
hh++;
for(int i=0;i<8;i++){
int xx=kx+dx[i];
int yy=ky+dy[i];
if(xx>=0&&xx
q[tt-1][0]=yy;
q[tt-1][1]=xx;
d[yy][xx]=d[ky][kx]+1;
cin>>n>>m>>y>>x>>t>>s;
tt++;
d[y][x]=1;
q[0][1]=x-1;
q[0][0]=y-1;
bfs();
cout<
}
边栏推荐
- 深度剖析 Apache EventMesh 云原生分布式事件驱动架构
- 数据库的备份与恢复「建议收藏」
- 算法---整数替换(Kotlin)
- MATLB|And her ups and downs and finally reached the peak of life [Romantic Journey]
- Project (7) - PolarSeg point cloud semantic segmentation
- Win11怎么关闭系统保护功能?系统保护还原功能怎么关闭?
- Fury:一个基于JIT动态编译的高性能多语言原生序列化框架
- 源码编译安装LAMP和LNMP
- 阿雷的血压有些低
- Why don't suggest you run in Docker Mysql?
猜你喜欢
随机推荐
从TRPO到PPO(理论分析与数学证明)
E - Sugoroku 3(期望dp)
[SUCTF 2019]CheckIn (.htaccess和.user.ini)
[Cloud native] Kubernetes orchestration tools
【毕业设计】 基于Stm32的家庭智能监控系统 - 单片机 图像识别 人体检测 AI
C语言学习之旅 【操作符(残缺版)】
Creo5.0 introductory tutorial free material
C语言--数据的存储(上)
LeetCode常见题型——链表
-象棋比赛-
阿雷的血压有些低
【数据存储】signed,unsigned到底怎么区分?如何计算?
聚焦热点 | ISC 2022软件供应链安全治理与运营论坛圆满落幕
Impala 疑问
【猜凶手,猜名次,杨辉三角】经典小学奥数的代码逻辑是什么?
服装店管理系统如何推送活动?
微服务【同步和异步通讯详解】第6章
ES6 Beginner to Mastery #13: Extension Methods for Arrays 2
手把手教你编写性能测试用例
共创 Ray 中文社区,Ray Forward Meetup 2022 直播邀你参加!

![[C language] In-depth understanding of pointers and arrays (issue 4)](/img/22/ad31b47bb8cc1722121959efddefd5.png)







![[C language] Address book](/img/56/a72900c22b965947ee88256d8f6c21.jpg)