当前位置:网站首页>Informatics Orsay all in one 1360: strange lift
Informatics Orsay all in one 1360: strange lift
2022-06-28 05:15:00 【Junyi_ noip】
【 Topic link 】
ybt 1360: Strange elevator (lift)
Luogu P1135 Strange elevator
【 Topic test site 】
1. Guang Shu
【 Their thinking 】
remember k[i] For the first time i The number marked on the floor .
This problem is similar to the problem of finding the shortest path in a maze , This problem can be solved by extensive search .
Let the node contain the number of floors x And the number of keystrokes s, First let the starting floor a And the number of keystrokes 0 The team . One node per team u, At this time, on the floor u.x, The next accessible floor is u.x+k[u.x] And u.x-k[u.x], As long as this floor exists , And I haven't visited , Then the number of floors of the new node is the next possible floor , The number of keystrokes of the new node is added to the number of keystrokes of the original node 1, Join the node in the team .
If the number of floors of the outgoing node is the target floor b, Then the number of keystrokes of this node is from a To b Minimum number of keystrokes .
【 Solution code 】
solution 1: Guang Shu
#include<bits/stdc++.h>
using namespace std;
#define N 205
struct Node
{
int x, s;//x: Floor number s: Number of buttons
Node(){
}
Node(int a, int b):x(a), s(b){
}
};
int n, a, b, np, k[N];
bool vis[N];//vis[i]: The first i The position has passed
int bfs()
{
queue<Node> que;
vis[a] = true;
que.push(Node(a, 0));// The initial state : In the a layer , Press 0 Time
while(que.empty() == false)
{
Node u = que.front();
que.pop();
if(u.x == b)
return u.s;
int x[2] = {
u.x + k[u.x], u.x - k[u.x]};// Two possible next arrival floors
for(int i = 0; i < 2; ++i)
{
if(x[i] >= 1 && x[i] <= n && vis[x[i]] == false)
{
vis[x[i]] = true;
que.push(Node(x[i], u.s + 1));
}
}
}
return -1;// If it doesn't arrive b layer
}
int main()
{
cin >> n >> a >> b;
for(int i = 1; i <= n; ++i)
cin >> k[i];
cout << bfs();
return 0;
}
边栏推荐
- Hundreds of lines of code to implement a script interpreter
- MySQL export database dictionary to excel file
- Sqlmap tool user manual
- BioVendor sRAGE抗体解决方案
- Is it enough for the project manager to finish the PMP? no, it isn't!
- [leetcode] 12. Integer to Roman numeral
- SlicePlane的Heading角度与Math.atan2(y,x)的对应转换关系
- Learning Tai Chi Maker - mqtt Chapter 2 (V) heartbeat mechanism
- PMP考试成绩多久出来?这些你务必知道!
- How does the power outlet transmit electricity? Simple problems that have plagued my little friend for so many years
猜你喜欢

Biovendor sRAGE protein solution

Gorm transaction experience

Binary sort tree: BST
![[leetcode] 12. Integer to Roman numeral](/img/3e/815f24a85a3333ce924acee1856f62.png)
[leetcode] 12. Integer to Roman numeral

基于订单流工具,我们能看到什么?

Extjs图书管理系统源码 智能化图书管理系统源码

Have you finished the examination of level II cost engineer? There are also qualification regulations!

JS 文本框失去焦点修改全半角文字和符号

Dart learning - functions, classes

SlicePlane的Heading角度与Math.atan2(y,x)的对应转换关系
随机推荐
2022 high altitude installation, maintenance and removal examination questions and answers
The short video local life section has become popular. How to grasp the new opportunities?
2022年材料员-通用基础(材料员)操作证考试题库及答案
Have you finished the examination of level II cost engineer? There are also qualification regulations!
Cgo+gsoap+onvif learning summary: 8. Summary of arm platform cross compilation operation and common problems
二级造价工程师考试还没完?还有资格审核规定!
gsap的简单用法
Hundreds of lines of code to implement a script interpreter
Unity out ref params
[JVM series] JVM tuning
Study on modified triphosphate: lumiprobe amino-11-ddutp
学习太极创客 — MQTT 第二章(五)心跳机制
二级造价工程师证书含金量到底有多高?看这些就知道了
创新之源 理解通透 二
Metartc5.0 API programming guide (I)
高通平台 Camera 之 MCLK 配置
MCLK configuration of Qualcomm platform camera
Docker安装Mysql5.7并开启binlog
The number of small stores in Suning has dropped sharply by 428 in one year. Zhangkangyang, the son of Zhang Jindong, is the actual controller
wordpress zibll子比主题6.4.1开心版 免授权