当前位置:网站首页>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>边栏推荐
- unittest自动化测试框架总结
- 数据库分析与优化
- 如何解决图像分类中的类别不均衡问题?不妨试试分开学习表征和分类器
- Silver circ: letter with material life insurance products should be by the insurance company is responsible for the management
- 【21天学习挑战赛】冒泡排序与插入排序
- 数字孪生助力智慧城市可视化建设
- golang 源码分析:juju/ratelimit
- J9 digital theory: the Internet across chain bridge has what effect?
- 网络协议介绍
- C# Barrier类
猜你喜欢

接口测试常用工具及测试方法(入门篇)

TPAMI2022 | TransCL: based on the study the compression of the Transformer, more flexible and more powerful

姑姑:给小学生出点口算题

「 每日一练,快乐水题 」1374. 生成每种字符都是奇数个的字符串

"Weekly Translate Go" This time we have something different!-- "How to Code in Go" series launched

Fiddle设置接口数据用指定工具查看;Sublime Text设置json数据格式化转换

Li Mu hands-on learning deep learning V2-bert and code implementation

信息学奥赛一本通(1259:【例9.3】求最长不下降序列)

OpenCV开发中的内存管理问题

.NET性能优化-你应该为集合类型设置初始大小
随机推荐
笑话:如果你在河边等待得足够久,你会看到你的敌人的尸体漂过,是怎么翻译出来的?
Parse the commonly used methods in the List interface that are overridden by subclasses
Bena的生命周期
Flutter 常见异常分析
你是几星测试/开发程序员?技术型选手王大拿......
setup syntax sugar defineProps defineEmits defineExpose
传感器工作原理
数字孪生助力智慧城市可视化建设
Leetcode刷题——23. 合并K个升序链表
pytorch的tensor创建和操作记录
太魔人招新啦|快来加入我们吧!
AI Scientist: Automatically discover hidden state variables of physical systems
The time series database has been developed for 5 years. What problem does it need to solve?
10 种最佳 IDE 软件 ,你更忠爱哪一个?
六石管理学:入门机会只有一次,先把产品做好
Helm基础知识
「每周译Go」这次我们来点不一样的!--《How to Code in Go》系列上线
ALV report learning summary
Soft Exam ----- UML Design and Analysis (Part 2)
unittest自动化测试框架总结