当前位置:网站首页>-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<
}
边栏推荐
猜你喜欢
随机推荐
go语言的并发原理(goroutine)
漫谈缺陷管理的自动化实践方案
C language learning journey [operator (incomplete version)]
渗透测试与攻防对抗——漏洞扫描&逻辑漏洞(Part1)
2022金九银十工作潮,怎么样才能成功跳槽面试拿到高薪呢?
Biotin-Cy2 Conjugate,生物素-Cy2 偶联物_Cy2 生物素偶联物
Distributed database problem (2): data replication
Redis-基本介绍/linux下环境配置/配置文件
第十二,十三章 mysql数据类型,视图的课后练习
基于ABP的AppUser对象扩展
Leetcode80. 删除有序数组中的重复项 II
redis distributed lock code example
关于HBuilder X鼠标变为_ 替换字符的问题
解锁时间生成与比较
【猜凶手,猜名次,杨辉三角】经典小学奥数的代码逻辑是什么?
[C language] Address book "Static Memory Version"
Impala 疑问
为什么不建议你在 Docker 中跑 Mysql ?
[NCTF2019]True XML cookbook-1|XXE漏洞
Creo5.0入门教程赠素材









