HDU - 1548 A strange lift(dfs)

【iOS开发】dyld: Symbol not found: ___chkstk_darwin 问题解决 【iOS开发】dyld: Symbol not found: ___chkstk_darwin 问题解决 Xcode 13.2.1 运行到iOS12.x版本上崩溃报错如下:dyld: Symbol not found: ___chkstk_darwin dyld: Symbol not found: ___chkstk_darwin Referenced from: /private/var/containers/Bundle/Application/A424CEFD-51DB-450E-9D62-B8 阅读详情

There is a strange lift.The lift can stop can at every floor as you want, and there is a number Ki(0 <= Ki <= N) on every floor.The lift have just two buttons: up and down.When you at floor i,if you press the button “UP” , you will go up Ki floor,i.e,you will go to the i+Ki th floor,as the same, if you press the button “DOWN” , you will go down Ki floor,i.e,you will go to the i-Ki th floor. Of course, the lift can’t go up high than N,and can’t go down lower than 1. For example, there is a buliding with 5 floors, and k1 = 3, k2 = 3,k3 = 1,k4 = 2, k5 = 5.Begining from the 1 st floor,you can press the button “UP”, and you’ll go up to the 4 th floor,and if you press the button “DOWN”, the lift can’t do it, because it can’t go down to the -2 th floor,as you know ,the -2 th floor isn’t exist.
Here comes the problem: when you are on floor A,and you want to go to floor B,how many times at least he has to press the button “UP” or “DOWN”?
Input
The input consists of several test cases.,Each test case contains two lines.
The first line contains three integers N ,A,B( 1 <= N,A,B <= 200) which describe above,The second line consist N integers k1,k2,…kn.
A single 0 indicate the end of the input.
Output
For each case of the input output a interger, the least times you have to press the button when you on floor A,and you want to go to floor B.If you can’t reach floor B,printf “-1”.
Sample Input

5 1 5
3 3 1 2 5
0

Sample Output

3

题意描述:给出三个数分别是n,a,b,然后再给出1~n层电梯在每一层能上或者能下的楼层数,然后问你按照给出的这些操作,电梯能否从a到b。如果能输出操作的次数,不能输出-1。

剪枝的操作

if(x<1||x>200)
		return ;
	if(x==b)
	{
		if(step<count)
		{
			count=step;
			flag=1;
		}
		return ;
	}
	if(book[x]<=step)
		return ;
	book[x]=step;

注意:不能简单的认为电梯就只能到达n层,具体有多少层看题上给出的条件。这个电梯可以一直上然后再下来,只要最终电梯到b就可以了。

#include<stdio.h>
#include<string.h>

int n,next[210],a,b;
int book[210],count;
int flag,inf=99999999;

void dfs(int x,int step)
{
	if(x<1||x>200)
		return ;
	if(x==b)
	{
		if(step<count)
		{
			count=step;
			flag=1;
		}
		return ;
	}
	if(book[x]<=step)
		return ;
	book[x]=step;
	dfs(x-next[x],step+1);
	dfs(x+next[x],step+1);
	return ;
}

int main(void)
{
	int i;
	while(~scanf("%d",&n))
	{
		flag=0;
		if(n==0)
			break;
			scanf("%d%d",&a,&b);
		for(i=1;i<=n;i++)
		{
			scanf("%d",&next[i]);
			book[i]=inf;
		}
		 count=inf;
		dfs(a,0);
		if(flag==1)
			printf("%d\n",count);
		else
		
			printf("-1\n");
	}
	return 0;
}
白话机器学习算法理论+实战番外篇之Xgboost 1. 写在前面 如果想从事数据挖掘或者机器学习的工作,掌握常用的机器学习算法是非常有必要的,在这简单的先捋一捋, 常见的机器学习算法: 监督学习算法:逻辑回归,线性回归,决策树,朴素贝叶斯,K近邻,支持向量机,集成算法Adaboost等 无监督算法:聚类,降维,关联规则, PageRank等 我前面已经尝试用最白话的语言完成了一个白话机器学习算法理论+实战系列,这个系列已经基本包含了上面这些算... 阅读详情

相关推荐

【Apollo规划模块探秘】—— 场景(Scenario)驱动的决策引擎

本文深入解析了Apollo自动驾驶平台规划模块的核心机制——场景(Scenario)驱动的决策引擎。文章通过类比日常驾驶,阐述了规划模块如何像经验丰富的司机一样,根据不同的路况(如车道跟随、无保护左转)切换不同的“驾驶模式”。重点剖析了场景管理器(ScenarioManager)如何基于感知信息进行场景判断与切换,以及“场景-阶段-任务”双层状态机如何精密协作,实现灵活、高效且安全的轨迹规划。

rnn9storyteller的博客 278

HDU1548:A strange lift(Dijkstra && BFS)

Problem Description There is a strange lift.The lift can stop can at every floor as you want, and there is a number Ki(0 <= Ki <= N) on every floor.The lift have just two buttons: up and down.When yo

ACM!荣耀之路! 1万+

【FreeRTOS】FreeRTOS 源码学习笔记 (3)队列 及 xQueueGenericSend分析

引言 本篇又不写调度器了,准备先整理整理“队列“,无他,就觉得这个很有用,自己写应用层代码的时候,队列要用的比较多,之前一直用一个自己写的环形buffer,里面nReadIndex,nWriteIndex,nFreeIndex来管理总觉得不够“官方”,这次看到一个如此成熟的队列,还是忍不住先分析一下。 ...

YoYo的桃子树 5103

A strange lift HDU - 1548(迪杰斯特拉3)

有一天桐桐做了一个梦,梦见了一种很奇怪的电梯。 大楼的每一层楼都可以停电梯,而且第i层楼(1≤i≤N)上有一个数字K;(0≤Ki≤N)。 电梯只有四 个按钮:开,关,上,下。上下的层数等于当前楼层上的那个数字。当然,如果不能满足要求,相应的按钮就会失灵。 例如:3 3 1 2 5代表了Ki (K1=3,K2=3,…),从一楼开始。在一楼,按 “上” 可以到4楼,按 “下” 是不起作用的,因为没有-...

博客 290

资治通鉴:文言文、白话文对照读本

介绍一处可以免费下载资治通鉴的网址,该文献共20卷,排版为左边是文言文,右边是白话文翻译,对照阅读非常方便。下面是1-20卷的链接地址:第一卷:http://www.docin.com/p-9705067.html 第二卷:http://www.docin.com/p-9705979.html 第三卷:http://www.docin.com/p-9709382.html 第四卷:

aiwis的专栏 2548

大一Python之循环解决实际问题

pythin之循环解决实际问题

weixin_66263546的博客 2287

杭电 HDU ACM 1548 A strange lift(简单广搜)

C - A strange lift Time Limit:1000MS    Memory Limit:32768KB    64bit IO Format:%I64d & %I64u SubmitStatusPracticeHDU 1548 Description There is a strange lift.The lift can stop can at ev

舒哥的blog 1945

IEEE Access 上岸指南,附含泪整理的 cover letter 、沟通邮件、终版文档等资料包

终于上岸了! 我是一个小硕,本科期间发表过两篇水文,奈何学校有更高的毕业要求,只能硬着头皮尝试一下 SCI。 想投 IEEE Access 的朋友都应该知道 小木虫论坛 对这个期刊的讨论,褒贬不一,有的人说是大水刊,有的人说有难度。 比如: @wow_: 不可否认,灌水期刊。只要之前中过一篇,再投基本没有不录用的!我们实验室其他老师说过一区除外的收费期刊都应该禁止灌水。 @pssp: 审稿人还...

kurryluo的博客 1万+

A strange lift(HDU-1548)(bfs实现)

Problem Description There is a strange lift.The lift can stop can at every floor as you want, and there is a number Ki(0 <= Ki <= N) on every floor.The lift have just two buttons: up and d...

Alex_McAvoy的博客 550

【MATLAB强化学习工具箱】学习笔记--在Simulink环境中训练智能体Create Simulink Environment and Train Agent

Simulink中便于搭建各类动力学与控制模型,通过将原有的控制器替换为AI控制器,可以方便使用已有模型,提供增量效果。 本节的重点是如何引入Simulink模型作为env,其他的内容在之前的文章中已有说明。 以水箱模型watertank为例,如下图所示: 采用PI控制器,控制效果如下所示: 将此PI控制器替换为神经网络控制器后,系统架构如下图所示: 具体替换策略如下所示: (1)删去PID控制器; (2)增加RL Agent模块; (3)观测器模块: 观测向量为:,其中...

bear_miao的博客 1万+

收放卷伺服控制系统详细算法介绍(电子齿轮+张力PID卷绕轴控制功能块)

收放卷控制系统涉及的内容非常多,这里我们介绍全伺服系统利用电子齿轮指令实现主从轴的比例随动速度控制,收放卷控制算法介绍常用链接如下1、收放卷+排线控制收放卷+排线控制系统框图-优快云博客文章浏览阅读24次。1、收放卷前馈量计算FC收放卷前馈量计算FC(CODESYS ST源代码)-优快云博客文章浏览阅读16次。1、收放卷前馈量计算FC(博途PLC):收放卷前馈量计算FC(梯形图+SCL代码)-优快云博客文章浏览阅读534次。2、收放卷前馈量计算FC。

RXXW_Dor的博客 3120

ACM-BFS之A strange lift——hdu1548

ACM BFS A strange lift hdu1548

继续激情,继续奋斗。 1906

置顶必读(1) | 《YOLOv26实战:从入门到深度优化》专栏导读与完整目录导航(持续更新中)

🏆 本文收录于 《YOLOv26实战:从入门到深度优化》 专栏。 本专栏系统梳理并持续复现 YOLOv26 官方特性、核心改进、多任务支持、部署优化与行业落地,内容坚持 持续更新 + 深度拆解 + 工程落地导向,不仅讲“怎么用”,更讲“为什么这样设计、如何真正落地到项目中”。

**My Coding Family** 9万+

HDU/HDOJ 1548 A strange lift BFS,DFS

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1548 我用两种方法做,DFS没有AC,不知道错在哪里,贴出来有大神撸过不吝赐教,第二种经典方法BFS过了,76MS 360k,思路都很简单,也是一道很规范的广度优先搜索。 代码: BFS: #include #include using namespace std; int n,a

R_xiaozhu_Q的专栏 1438

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

HDU- 1548 A strange lift (DFS)

                                                A strange lift Problem Description There is a strange lift.The lift can stop can at every floor as you want, and there is a number Ki(0 &lt;= Ki &lt;=...

K.X的博客 558

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

HDU-1548 A strange lift (DFS)

There is a strange lift.The lift can stop can at every floor as you want, and there is a number Ki(0 &lt;= Ki &lt;= N) on every floor.The lift have just two buttons: up and down.When you at floor i,if...

galesaur_wcy 287

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

A strange lift(HDU-1548)(dfs实现)

Problem Description There is a strange lift.The lift can stop can at every floor as you want, and there is a number Ki(0 <= Ki <= N) on every floor.The lift have just two buttons: up and d...

Alex_McAvoy的博客 527

HDU-1548-A strange lift(dfs)

A strange lift   Problem Description: There is a strange lift.The lift can stop can at every floor as you want, and there is a number Ki(0 &lt;= Ki &lt;= N) on every floor.The lift have just two but...

1339

HDU 1548- A strange lift (DFS)

There is a strange lift.The lift can stop can at every floor as you want, and there is a number Ki(0 &lt;= Ki &lt;= N) on every floor.The lift have just two buttons: up and down.When you at floor i,if...

仙女的博客 239

HDU-1548 A Strange Lift

HDU-1548 A Strange Lift 题意:一共N层电梯,到达第x层电梯可以向上或向下移动a[x]的层数,问最短需要几次操作到达指定层数。 主要是要处理好操作数量的动态变化关系,莽++肯定会出问题 dfs,bfs,最短路dijkstra 貌似都能做 1.bfs #include<cstdio> #include<cstring> #include<algor...

想要一只银渐层 260

A strange lift HDU - 1548(Dijkstra/SPFA/BFS/DFS)

法一:Dijkstra+邻接表 对于每一层,在它与它up和down可到的两个楼层间建边(down的楼层要大于0),权值为1,求最短路。(代码中注释的地方是默写模板时出错的地方,要特别注意) #include<bits/stdc++.h> using namespace std; typedef pair<int,int> PII; const int N=205,M...

skyline的分享专栏 190

hdu 1548 A strange lift(最短路或DFS)

题目:         链接:点击打开链接 题意: 思路:         这也是最短路径的问题,与以往的最短路径有所不同,开始时一看是让求步数,以为是搜索题,就用广搜做,也运行对了,但是提交不上,说的是使用内存超出限制,所以得用其他法,这题首先要做的是把在某一层向上向下能一步到达的层数用数组对应起来,然后就是dijkstra算法求最短路径了。 代码: #include #inclu

young TO challenge! 458

HDU - 1548 A strange lift

https://vjudge.net/problem/HDU-1548 HDU - 1548 A strange lift题目分析AC代码 题目 There is a strange lift.The lift can stop can at every floor as you want, and there is a number Ki(0 <= Ki <= N) on every floor.The lift have just two buttons: up and down.When

斯文~ 349

HDU 1548 A strange lift (搜索)

链接http://acm.hdu.edu.cn/diy/contest_showproblem.php?pid=1019&cid=34750 Problem Description There is a strange lift.The lift can stop can at every floor as you want, and there is a number Ki(0 &l...

bravo的博客 358

HDU 1548 A strange lift (搜索-深搜、广搜)

There is a strange lift.The lift can stop can at every floor as you want, and there is a number Ki(0 <= Ki <= N) on every floor.The lift have just two buttons: up and down.When you at floor i,if you press the button "UP" , you will go up Ki floor,i.e,you w

凌风 3489

hdu 1548 A strange lift (bfs)

A strange lift Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 8550    Accepted Submission(s): 3241 Problem Description There is a stra

Hadis_yuki 908
上一篇: POJ1797---Heavy Transportation(Dijkstra的变形)
下一篇: ZOJ - 1649 Rescue(dfs)
鳳九~
博客等级 码龄8年 1384粉丝 215原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值