当前位置:网站首页>-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<
}
边栏推荐
猜你喜欢

游泳馆系统次卡的设置有哪些细节?

【Infiltration tool】Browser data export tool

Creo5.0入门教程赠素材

Today's sleep quality record 61 points

为什么不建议你在 Docker 中跑 Mysql ?

Leetcode82. 删除排序链表中的重复元素 II
![[C language] Address book](/img/56/a72900c22b965947ee88256d8f6c21.jpg)
[C language] Address book "Static Memory Version"

Win11怎么关闭系统保护功能?系统保护还原功能怎么关闭?

【猜凶手,猜名次,杨辉三角】经典小学奥数的代码逻辑是什么?

最高月薪15K,谁有历经千辛万苦的意志,谁就能收获属于自己的成功~
随机推荐
走出迷宫的最少步数2
知行合一的时候
最高月薪15K,谁有历经千辛万苦的意志,谁就能收获属于自己的成功~
【obs】obsqsv11 硬编 及与metartc codec对比
Leetcode83. 删除排序链表中的重复元素
7. type( )函数——查询数据类型
Creo5.0 introductory tutorial free material
NTU General Database-Gbase-8a-Learning-04-Deploying Distributed Clusters
Leetcode82. 删除排序链表中的重复元素 II
足不出户也能看星空
【问题解决】训练和验证准确率很高,但测试准确率很低
Project (7) - PolarSeg point cloud semantic segmentation
3.1 - 程序设计语言 3.2 - 高级语言的特点及引用 3.3 - 静态/动态类型语言
基于ABP的AppUser对象扩展
3.9 - 正规表达式和正规集 3.10 - 有限自动机
Kubernetes 开发环境比对
构建平衡二叉树「建议收藏」
错误提示:Syntax error on token “function”, delete this token
【毕业设计】基于ESP32的在线墨水屏桌面摆件 -物联网 单片机 嵌入式
CAS:851113-28-5 (生物素-ahx-ahx-酪胺)