当前位置:网站首页>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>边栏推荐
猜你喜欢

Parse the commonly used methods in the List interface that are overridden by subclasses

J9 digital theory: the Internet across chain bridge has what effect?

56.【全局变量和局部变量专题】

In action: 10 ways to implement delayed tasks, with code!

Translate My Wonderful | July Moli Translation Program Winners Announced

Axure9的元件用法

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

奥特学园ROS笔记--7(289-325节)

【实战 已完结】WPF开发自动化生产管理平台

SQL Server实现group_concat功能
随机推荐
Translate My Wonderful | July Moli Translation Program Winners Announced
4 kmiles join YiSheng group, with more strong ability of digital business, accelerate China's cross-border electricity full domain full growth
六石管理学:入门机会只有一次,先把产品做好
EasyExcel dynamic parsing and save table columns
golang源码分析:time/rate
Flutter 常见异常分析
李沐动手学深度学习V2-bert预训练数据集和代码实现
Thread线程类基本使用(上)
In action: 10 ways to implement delayed tasks, with code!
OP analysis and design
Flutter with internationalized adapter automatically generated
软件测试的流程规范有哪些?具体要怎么做?
SQL Server安装教程
Parse common methods in the Collection interface that are overridden by subclasses
Parse the commonly used methods in the List interface that are overridden by subclasses
成为黑客不得不学的语言,看完觉得你们还可吗?
交 叉 数 组
TPAMI2022 | TransCL: based on the study the compression of the Transformer, more flexible and more powerful
力扣每日一题-第46天-344. 反转字符串
网络协议介绍