当前位置:网站首页>-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<
}
边栏推荐
- openEuler 知:abi 检测
- Project (7) - PolarSeg point cloud semantic segmentation
- Leecode-205. 同构字符串
- The older tester has just passed the "hurdle" of being 35 years old, and I want to tell you something from my heart
- 博弈小游戏
- Copper's emotion
- 微服务【同步和异步通讯详解】第6章
- EL表达式
- MATLB|And her ups and downs and finally reached the peak of life [Romantic Journey]
- 输入的这些数是否对称
猜你喜欢
Leetcode80. 删除有序数组中的重复项 II
[C language] Address book "Static Memory Version"
FITC标记生物素(FITC-生物素|CAS:134759-22-1)有哪些知识了?
dlopen failed: library "libtaml.so" not found
LSTM-based distributed energy generation prediction (Matlab code implementation)
Linux安装Oracle和postgrepSQL数据库
Leetcode82. 删除排序链表中的重复元素 II
C语言--数据的存储(上)
【毕业设计】基于ESP32的在线墨水屏桌面摆件 -物联网 单片机 嵌入式
Service Discovery @EnableDiscoveryClient
随机推荐
deepstream学习笔记(三):deepstream-imagedata-multistream解析与接入适配yolov5模型测试
组件传值-作用域插槽
安全知识培训——消防安全
02|运算符
【C语言】通讯录《静态内存版本》
20220808-一些想法
从TRPO到PPO(理论分析与数学证明)
聚焦热点 | ISC 2022软件供应链安全治理与运营论坛圆满落幕
收银管理软件如何做好员工管理?
dlopen failed: library “libtaml.so“ not found
[C language] Address book "Static Memory Version"
3.1 - 程序设计语言 3.2 - 高级语言的特点及引用 3.3 - 静态/动态类型语言
Web性能测试模型小结
Description of AirFlow
线程的同步与互斥
JSP简介
【毕业设计】 基于Stm32的家庭智能监控系统 - 单片机 图像识别 人体检测 AI
Redis-基本介绍/linux下环境配置/配置文件
PEG 衍生物Biotin-PEG1-OH(cas:95611-10-2,2-生物素氨基乙醇)优势说明
NTP SERVICE TASK 在GWserver配置、启用NTP服务,为当前环境提供时钟同步服务,Client主机可以从该服务器同步时间。