当前位置:网站首页>-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<
}
边栏推荐
- Redis 大 key 要如何处理?
- 【猜凶手,猜名次,杨辉三角】经典小学奥数的代码逻辑是什么?
- 有PEG-Biotin参与的(CAS:1778736-18-7)Biotin-PEG4-OH广泛用于分子靶点检测
- 大龄测试员刚迈过了 35 岁这个“坎儿”,和大家说点儿心里话
- Redisson 分布式锁
- 温度响应性纳米水凝胶光子品体/纤维素修饰荧光水凝胶/载脂质体水凝胶的制备方法
- 服装店管理系统如何推送活动?
- [C language] In-depth understanding of pointers and arrays (issue 4)
- 最高月薪15K,谁有历经千辛万苦的意志,谁就能收获属于自己的成功~
- 足不出户也能看星空
猜你喜欢
由生物素参与的D-Biotinol,CAS号:53906-36-8具体特性说明
LSTM-based distributed energy generation prediction (Matlab code implementation)
拒绝“重复造轮子”,百度EasyDL让你玩转AI定制开发
CST Studio Suite 2021 software installation package and installation tutorial
WPF DataGrid 使用数据模板
3.1 - 程序设计语言 3.2 - 高级语言的特点及引用 3.3 - 静态/动态类型语言
最高月薪15K,谁有历经千辛万苦的意志,谁就能收获属于自己的成功~
数据的存储——C语言
温度响应性纳米水凝胶光子品体/纤维素修饰荧光水凝胶/载脂质体水凝胶的制备方法
深入理解Aarch64内存管理
随机推荐
ES6 Beginner to Mastery #13: Extension Methods for Arrays 2
【Django】缓存
天猫全网商品详情封装接口
Distributed database problem (2): data replication
3.9 - 正规表达式和正规集 3.10 - 有限自动机
LSTM-based distributed energy generation prediction (Matlab code implementation)
Biotin-Cy2 Conjugate,生物素-Cy2 偶联物_Cy2 生物素偶联物
西安生物素-四聚乙二醇-酰胺-4苯酚 浅黄色半固态
数字孪生智慧制造生产线项目实施方案,平台认知与概念
数据的存储——C语言
[C language] In-depth understanding of pointers and arrays (issue 4)
Solidity 智能合约入门
Leetcode82. 删除排序链表中的重复元素 II
The technical aspects of the byte have been passed, and the salary has been negotiated for 20K*13, but the result is still being brushed. I asked the HR why...
NTU General Database-Gbase-8a-Learning-04-Deploying Distributed Clusters
Redisson 分布式锁
《MySQL入门很轻松》第4章:数据表中存放的数据类型
LeetCode常见题型——链表
有PEG-Biotin参与的(CAS:1778736-18-7)Biotin-PEG4-OH广泛用于分子靶点检测
arm-4-裸板开发