当前位置:网站首页>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;
}
边栏推荐
- Leetcode 88: merge two ordered arrays
- Sqlmap tool user manual
- The latest examination questions and answers for the eight members (standard members) of Liaoning architecture in 2022
- QCOM LCD调试
- Lumiprobe细胞成像分析:PKH26 细胞膜标记试剂盒
- DPDK 源码测试时性能下降问题
- 2022西式面点师(高级)考试试题模拟考试平台操作
- Reactive dye research: lumiprobe af594 NHS ester, 5-isomer
- JS text box loses focus to modify width text and symbols
- Biovendor sRAGE antibody solution
猜你喜欢

Light collector, Yunnan Baiyao!

Docker安装Mysql5.7并开启binlog

2022年低压电工考题及答案

Biovendor sRAGE protein solution

How high is the gold content of grade II cost engineer certificate? Just look at this

如何从零设计一款牛逼的高并发架构(建议收藏)

【牛客网刷题系列 之 Verilog快速入门】~ 四选一多路器

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

Operation of simulated examination platform of G3 boiler water treatment recurrent training question bank in 2022

metaRTC5.0编程之p2p网络穿透(stun)指南
随机推荐
Carboxylic acid study: lumiprobe sulfoacyanine 7 dicarboxylic acid
2022年安全员-B证考试题库及答案
Simulation questions and answers of the latest national fire-fighting facility operators (primary fire-fighting facility operators) in 2022
2022年材料员-通用基础(材料员)操作证考试题库及答案
Learning Tai Chi Maker - mqtt Chapter II (VI) mqtt wills
Is it enough for the project manager to finish the PMP? no, it isn't!
开关电源电压型与电流型控制
Store inventory management system source code
Unity delegate
metaRTC5.0 API编程指南(一)
氨基染料研究:Lumiprobe FAM 胺,6-异构体
通过例子学习Rust
MySQL export query results to excel file
It is the latest weapon to cross the blockade. It is one of the fastest ladders.
2022年G3锅炉水处理复训题库模拟考试平台操作
Standard particle swarm optimization C language program
【微服务|OpenFeign】OpenFeign快速入门|基于Feign的服务调用
Opencv实现目标检测
Biovendor sRAGE protein solution
BioVendor sRAGE抗体解决方案