当前位置:网站首页>-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<
}
边栏推荐
猜你喜欢
随机推荐
[C language] Address book "Static Memory Version"
【CAS:41994-02-9 |Biotinyl tyramide】生物素基酪氨酰胺价格
Description of AirFlow
-象棋比赛-
deepstream学习笔记(三):deepstream-imagedata-multistream解析与接入适配yolov5模型测试
NTP SERVICE TASK 在GWserver配置、启用NTP服务,为当前环境提供时钟同步服务,Client主机可以从该服务器同步时间。
Redis 非关系型数据库学习(一) ---- Redis 的安装
nfs配置
生物素叠氮化物中的(CAS:1527486-16-3TAMRA-azide-PEG3-Biotin)反应的特点!
Today's sleep quality record 61 points
Leetcode82. 删除排序链表中的重复元素 II
《痞子衡嵌入式半月刊》 第 60 期
E - Sugoroku 3(期望dp)
Fury:一个基于JIT动态编译的高性能多语言原生序列化框架
3.4 - 编译与解释 3.5 - 编译过程 3.8 - 文法
Service Discovery @EnableDiscoveryClient
游泳馆系统次卡的设置有哪些细节?
【「收藏」Oracle 数据库安装】
LSTM-based distributed energy generation prediction (Matlab code implementation)
【剑指offer】第一题 第二题