当前位置:网站首页>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;
}
边栏推荐
- Biovendor sRAGE antibody solution
- 2022 low voltage electrician examination questions and answers
- 证明素数/质数有无限多个
- 店铺进销存管理系统源码
- 如何从零设计一款牛逼的高并发架构(建议收藏)
- 2022 high altitude installation, maintenance and removal examination questions and answers
- 乔布斯在斯坦福大学的演讲稿——Follow your heart
- RxSwift --(1)创建一个项目
- Gorm transaction experience
- BioVendor sRAGE蛋白解决方案
猜你喜欢

metaRTC5.0编程之p2p网络穿透(stun)指南

The short video local life section has become popular. How to grasp the new opportunities?

A guide to P2P network penetration (stun) for metartc5.0 programming

Simulation questions and answers of the latest national fire-fighting facility operators (primary fire-fighting facility operators) in 2022

The latest examination questions and answers for the eight members (standard members) of Liaoning architecture in 2022

DH parameters of robotics and derivation using MATLAB symbolic operation

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

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

How to learn programmable logic controller (PLC)?

学习太极创客 — MQTT 第二章(四)ESP8266 保留消息应用
随机推荐
Pcr/qpcr research: lumiprobe dsgreen is used for real-time PCR
Study on modified triphosphate: lumiprobe amino-11-ddutp
Function reentry caused by Keil C51's data overlaying mechanism
Extjs library management system source code intelligent library management system source code
sqlmap工具使用手册
Binary sort tree: BST
程序员-放羊娃
短视频本地生活版块成为热门,如何把握新的风口机遇?
DH parameters of robotics and derivation using MATLAB symbolic operation
2022 safety officer-b certificate examination question bank and answers
[skywalking] learn distributed link tracking skywalking at one go
SlicePlane的Heading角度与Math.atan2(y,x)的对应转换关系
Hundreds of lines of code to implement a script interpreter
C语言中函数是什么?编程中的函数与数学中的函数区别?理解编程语言中的函数
学习太极创客 — MQTT 第二章(六)MQTT 遗嘱
JS text box loses focus to modify width text and symbols
gsap的简单用法
2022电力电缆判断题模拟考试平台操作
【LeetCode】12、整数转罗马数字
Latest Windows version 5.0.14 of redis