当前位置:网站首页>Informatics Olympiad All-in-One (1257: Knight Moves)
Informatics Olympiad All-in-One (1257: Knight Moves)
2022-08-02 23:36:00 【The oranges teacher】
1257: Knight Moves
Time Limit: 1000 ms Memory Limit: 65536 KB
Commits: 6149 Passes: 3100
【Title Description】
Enter nn to represent an n×n chessboard, enter the coordinates of the start position and the coordinates of the end position, and ask a knight to move the horse in the eight directions of the chessboardstep, how many steps can be passed from the start coordinate to the end coordinate.

[Enter]
First enter a nn, which represents the number of test samples.
There are three lines per test case.
The first line is the size L of the chessboard (4≤L≤300);
The second and third lines represent the starting and destination positions of the horse (0..L−1), respectively.
【Output】
The minimum number of steps the horse can move, output 00 when the starting position and the target position are the same.
【Sample input】
380 07 01000 030 50101 11 1【Example of output】
5280【Analysis】
Horse walking day, 8 directions, direction array (1,2),(1,-2),(-1,2),(-1,-2),(2,1),(2,-1),(-2,1),(-2,-1).
【Reference Code】
#include#include#includeusing namespace std;const int N=310;struct node{int x,y;int t;};int sx,sy; //Starting point coordinatesint ex,ey; //End point coordinatesint l; //chessboard sizeint dx[]={1,1,-1,-1,2,2,-2,-2}; //direction arrayint dy[]={2,-2,2,-2,1,-1,1,-1};bool vis[N][N]; //Access the arrayvoid bfs(){queue q; //application queuenode st;st.x=sx;st.y=sy;st.t=0;q.push(st); //The starting point joins the queuewhile(!q.empty()){node nt=q.front();if(nt.x==ex && nt.y==ey){cout<=0 && nx=0 && ny>t;while(t--){memset(vis,false,sizeof(vis));cin>>l;cin>>sx>>sy>>ex>>ey;vis[sx][sy]=true;bfs();}} a>边栏推荐
- The five classification of software testing
- 新增指令 v-memo
- 第一次进入前20名
- Geoip2 - golang golang source code analysis
- LM小型可编程控制器软件(基于CoDeSys)笔记二十五:plc的数据存储区(数字量输入通道部分)
- The time series database has been developed for 5 years. What problem does it need to solve?
- Xcode13.1运行工程报错fatal error: ‘IFlyMSC/IFly.h‘ file not found的问题
- Day12 接口和协议
- 顺序查找和折半查找,看这篇就够了
- 「每周译Go」这次我们来点不一样的!--《How to Code in Go》系列上线
猜你喜欢

广东省数字经济发展指引 1.0之建成数据安全保障体系

OP analysis and design

交 叉 数 组

实现fashion_minst服装图像分类

Five data structures of Redis and their corresponding usage scenarios

Triacetin是什么化学材料

框架设计:PC 端单页多页框架如何设计与落地

callback prototype __proto__

J9 Digital Currency Theory: Identifying Web3's New Scarcity: Open Source Developers

Day35 LeetCode
随机推荐
信息系统项目管理师必背核心考点(五十八)变更管理的主要角色
一次线上事故,我顿悟了异步的精髓
【21天学习挑战赛】冒泡排序与插入排序
[21 Days Learning Challenge] Bubble Sort and Insertion Sort
setup syntax sugar defineProps defineEmits defineExpose
Async的线程池使用的哪个?
Li Mu hands-on deep learning V2-BERT pre-training and code implementation
KDD 2022 | 深度图神经网络中的特征过相关:一个新视角
Triacetin是什么化学材料
Common tools and test methods for interface testing (Introduction)
特拉维夫大学 | Efficient Long-Text Understanding with Short-Text Models(使用短文本模型进行高效的长文本理解)
接口测试常用工具及测试方法(入门篇)
"Weekly Translate Go" This time we have something different!-- "How to Code in Go" series launched
数字孪生助力智慧城市可视化建设
In action: 10 ways to implement delayed tasks, with code!
Bena's life cycle
信息学奥赛一本通(1258:【例9.2】数字金字塔)
iframe------------frame-
C# Monitor类
网上那么多教人赚钱的方法,但是你实际上是靠什么赚钱的呢?