当前位置:网站首页>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>边栏推荐
- 「每周译Go」这次我们来点不一样的!--《How to Code in Go》系列上线
- ShardingSphere-proxy +PostgreSQL implements read-write separation (static strategy)
- 你所不知道的C#中的细节
- TPAMI2022 | TransCL: based on the study the compression of the Transformer, more flexible and more powerful
- ALV report learning summary
- Digital twins help visualize the construction of smart cities
- 美国爱荷华州立大学| Improving Distantly Supervised Relation Extraction by Natural Language Inference(通过自然语言推理改进远程监督关系提取)
- 框架设计:PC 端单页多页框架如何设计与落地
- 对话亚洲高校首个博士论文奖-裘捷中丨KDD2022
- Qt提升自定义控件,找不到头文件
猜你喜欢
框架设计:PC 端单页多页框架如何设计与落地
Implement fashion_minst clothing image classification
Li Mu hands-on learning deep learning V2-bert and code implementation
Day12 接口和协议
Translate My Wonderful | July Moli Translation Program Winners Announced
你是几星测试/开发程序员?技术型选手王大拿......
引用类型 ,值类型 ,小坑。
OP-5,输入/输出信号范围-一信号处理能力
SQL 嵌套 N 层太长太难写怎么办?
Parse common methods in the Collection interface that are overridden by subclasses
随机推荐
Redis cluster configuration
成为黑客不得不学的语言,看完觉得你们还可吗?
Linphone 被叫方如何解析来电SIP消息中的自定义头消息
iframe------------frame-
Li Mu hands-on learning deep learning V2-bert and code implementation
一次线上事故,我顿悟了异步的精髓
Li Mu hands-on deep learning V2-BERT pre-training and code implementation
广东省数字经济发展指引 1.0之建成数据安全保障体系
Bena's life cycle
ALV concept explanation
信息学奥赛一本通(1259:【例9.3】求最长不下降序列)
Details in C# you don't know
10 种最佳 IDE 软件 ,你更忠爱哪一个?
Parse the commonly used methods in the List interface that are overridden by subclasses
Day35 LeetCode
OP-5,输入/输出信号范围-一信号处理能力
APP自动化uiautomator2获取toast
实现fashion_minst服装图像分类
软件测试的流程规范有哪些?具体要怎么做?
「每周译Go」这次我们来点不一样的!--《How to Code in Go》系列上线