当前位置:网站首页>-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<
}
边栏推荐
猜你喜欢
游泳馆系统次卡的设置有哪些细节?
Biotin-Cy2 Conjugate,生物素-Cy2 偶联物_Cy2 生物素偶联物
Creo5.0入门教程赠素材
基于 LSTM 的分布式能源发电预测(Matlab代码实现)
聚焦热点 | ISC 2022软件供应链安全治理与运营论坛圆满落幕
mysql无法远程连接 Can‘t connect to MySQL server on ‘xxx.xxx.xxx.xxx‘ (10060 “Unknown error“)
WPF DataGrid 使用数据模板
WPF DataGrid using data templates
技术分享 | 接口自动化测试如何处理 Header cookie
selenium和驱动安装
随机推荐
Distributed database problem (2): data replication
ES6 Beginner to Mastery #13: Extension Methods for Arrays 2
Enhanced Deep Residual Networks for Single Image Super-Resolution
C语言学习之旅 【操作符(残缺版)】
When knowledge and action are one
Today's sleep quality record 61 points
《痞子衡嵌入式半月刊》 第 60 期
Spark基础【RDD单Value类型转换算子】
Redis-基本介绍/linux下环境配置/配置文件
win10重装系统后没声音怎么办?
【毕业设计】基于ESP32的在线墨水屏桌面摆件 -物联网 单片机 嵌入式
考柏的感慨
阿雷的血压有些低
c语言结构体、函数以及指针练习(简单通讯录)
abicc 知:API compatibility report 介绍
GoLang 使用 goroutine 停止的几种办法
【问题解决】训练和验证准确率很高,但测试准确率很低
Creo5.0 introductory tutorial free material
Tensor flow 踩坑记
足不出户也能看星空