当前位置:网站首页>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;
}
边栏推荐
- 2022电力电缆判断题模拟考试平台操作
- Learning Tai Chi Maker - mqtt Chapter 2 (V) heartbeat mechanism
- Sorting out some topics of modern exchange principle MOOC
- Feign通过自定义注解实现路径的转义
- Dart learning - functions, classes
- [microservices openfeign] openfeign quick start service invocation based on feign
- 2022年G3锅炉水处理复训题库模拟考试平台操作
- Keil C51的Data Overlaying机制导致的函数重入问题
- Function reentry caused by Keil C51's data overlaying mechanism
- 109. simple chat room 12: realize client-side one-to-one chat
猜你喜欢

店铺进销存管理系统源码

Learn Taiji Maker - mqtt Chapter 2 (IV) esp8266 reserved message application

IP datagram sending and forwarding process

Dart learning - functions, classes

别卷!如何高质量地复现一篇论文?

Excel将一行的内容进行复制时,列与列之间是用制表符“\t”进行分隔的

Pcr/qpcr research: lumiprobe dsgreen is used for real-time PCR

sqlmap工具使用手册

Store inventory management system source code

氨基染料研究:Lumiprobe FAM 胺,6-异构体
随机推荐
The latest examination questions and answers for the eight members (standard members) of Liaoning architecture in 2022
Light collector, Yunnan Baiyao!
Is it enough for the project manager to finish the PMP? no, it isn't!
Learn Taiji Maker - mqtt Chapter 2 (IV) esp8266 reserved message application
Reactive dye research: lumiprobe af594 NHS ester, 5-isomer
Opencv实现颜色检测
氨基染料研究:Lumiprobe FAM 胺,6-异构体
短视频本地生活版块成为热门,如何把握新的风口机遇?
It is the latest weapon to cross the blockade. It is one of the fastest ladders.
Blocking, non blocking, IO multiplexing select\poll\epoll
The heading angle of sliceplane is the same as that of math Corresponding transformation relation of atan2 (y, x)
Carboxylic acid study: lumiprobe sulfoacyanine 7 dicarboxylic acid
Voltage mode and current mode control of switching power supply
项目经理考完PMP就够了?不是的!
Dart学习——函数、类
Learning Tai Chi Maker - mqtt Chapter 2 (V) heartbeat mechanism
Store inventory management system source code
基于微信小程序的婚纱影楼门户小程序
BioVendor sRAGE Elisa试剂盒化学性质和技术研究
SlicePlane的Heading角度与Math.atan2(y,x)的对应转换关系