1:问题描述
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 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 is on floor A,and you want to go to floor B,how many times at least he havt 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

2:大致题意

一个电梯,只有上,下,两个按钮。而且上和下的层数是给定的,
给你起始位置和,结束位置。要判断是否可以到达。

3:思路

在某个楼层,分别将它上升和下降达到的楼层记录下来,放入队列里面。如果达到指定楼层就记录下来并结束。
要记得清空队列。

4:感想

这个题,我写的代码好像有不对的地方不过倒是ac了。。

5:ac代码

#include<iostream>
#include<string.h>
#include<set>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<math.h>
#include<string.h>
#include<sstream>
#include<stdio.h>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<queue>
#include<iomanip>
#include<cstdio>
using namespace std;
struct node
{int x ;int t ;
}n1,n2,m;
int c[2000],ww[2000];  //标记数组,和一个记录楼层状态的数组
int flag ;                 //记录能否到达目标楼层
int n , a , b ;          //n层,a,起始楼层,b,目的楼层
int main(  )
{while( scanf("%d" , &n ) , n ){if( n== 0 ) break ;        //结束cin>>a>>b;for( int i= 1;  i<= n ; i++ )     //初始化{ cin>>ww[i] ; c[i] = 0 ; }flag = 0 ;                      //初始为0n1.x = a ; n1.t = 0 ;        //把a开始所在楼层赋给结构体, 所走步数为0queue<node>Q;               //建立队列QQ.push(n1);                        //入队c[n1.x] = 1 ;          //标记已经走过while( !Q.empty() )       //直到为空为止{m = Q.front() ;            //把队列中第一个值赋给结构体变量mQ.pop();                   //出队if( m.x == b )            //如果到达终点便退出{ flag = 1 ; break ; }n1.x = m.x - ww[m.x];  //按向下的按钮n2.x = m.x + ww[m.x]; //按向上的按钮if( n1.x>0 && n1.x<= b && !c[n1.x] )//向下{n1.t = m.t + 1 ;         //步数加一c[n1.x] = 1 ;       //标记Q.push(n1);}if( n2.x>0 && n2.x<= b && !c[n2.x] )//向上{n2.t = m.t+1 ;c[n2.x] = 1 ;Q.push(n2);}}if( flag ) cout<<m.t<<endl;else cout<<"-1"<<endl;}return 0;
}

SDAU 搜索专题 13 A strange lift相关推荐

  1. hdu 1548 A strange lift

    A strange lift Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Tota ...

  2. A strange lift HDU - 1548(基础广搜)

    There is a strange lift.The lift can stop can at every floor as you want, and there is a number Ki(0 ...

  3. 2019.6.7 一场搜索专题的考试【including 洛谷·血色先锋队,入门OJ·兴建高铁,珠光宝气阁

    这次分数还好.但全是搜索题还没上200就有点打击人了--[本狸才177QAQ 血色先锋队/血色敢死队 传送门:洛谷P1332 & 入门OJ P2259 Description 邪魔天国领主复活 ...

  4. 远控免杀专题(13)-zirikatu免杀(VT免杀率39/71)

    声明:文中所涉及的技术.思路和工具仅供以安全为目的的学习交流使用,任何人不得将其用于非法用途以及盈利等目的,否则后果自行承担! 本专题文章导航 1.远控免杀专题(1)-基础篇:https://mp.w ...

  5. HDU A strange lift

    A strange lift Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Tota ...

  6. 【寒假训练/Java】搜索专题

    文章目录 题目链接 知识点 题目列表 快输 A - Knight Moves(BFS/双向BFS) B - 迷宫(一) C - 迷宫(二)(BFS) D - 老子的全排列呢 E - [NOIP2002 ...

  7. 【蓝桥杯】搜索专题总结——真题讲解

    写在前面 小伙伴们我们又见面啦~这篇文章拖了又拖,终于写完啦.这篇讲了几道蓝桥杯中考察DFS和BFS的真题,大家可以去看看前面两篇文章,对搜索讲的很详细.[一万字]蓝桥杯算法竞赛备考(一)--搜索专题 ...

  8. 花花酱leetcode 题目——搜索专题

    在刷完极客时间的算法题目之后,偶然看到了花花酱关于leetcode进入千题时代的一些刷题看法.决定跟着他的思路继续刷题. 要刷多少题 1 每个类型 10-20 如何刷题 1 同类型题目一起刷 2 看代 ...

  9. Depth-first Search深度优先搜索专题1

    104. Maximum Depth of Binary Tree 思路:顺着树的一个分支一直数层数直到叶子节点.DFS的思路.这个题目可以练习的是递归转迭代. 代码 695. Max Area of ...

最新文章

  1. Mysql学习之order by的工作原理
  2. 共享内存+Shellcode实现跨进程调用3环函数
  3. 鸿蒙系统和中标麒麟系统关系,操作系统有哪些 先有鸿蒙后有麒麟V10 为5G时代量身定做...
  4. 年度神作!这本Python 3.6的书刷爆朋友圈,网友:太香!
  5. 蚂蚁笔记 linux安装教程,简年14:蚂蚁笔记(Leanote)快速部署指南
  6. C语言 解析lrc歌词文件
  7. 深度强化学习-策略梯度算法深入理解
  8. python输出n的32次方_在Python中,如何将2的32次方-1的值存放到g中?
  9. php 查询8到10点之间的数据,一个人的命运决定于晚上8点到10点之间
  10. 十秒钟刷完云班课的一节视频
  11. 2021哔哩哔哩1024程序员节日第一弹:算法与安全
  12. 科学史十五讲(江晓原)
  13. 图像信号处理器及其架构演进
  14. 我在博客大巴上新开了一个博客
  15. Java 面试/笔试题神整理 [Java web and android]
  16. Mac 安装Homebrew慢的问题解决
  17. 1.gstreamer USB摄像头保存至图片及视频
  18. Bugtags - App 测试 · 从未如此简单
  19. 织梦dedecms模板文件在哪
  20. plantuml使用

热门文章

  1. 数据库系统概念--创建数据库
  2. Android Studio程序运行流程(大白话迅速入门)
  3. 361度宣布新晋世界拳王徐灿为品牌形象代言人
  4. 【计算机网络】ip地址、分类及什么样的ip主机地址可以分配给主机使用
  5. Mactype - 让 Windows 字体更漂亮
  6. 【有感】今日阅读我知乎轮子哥“vczh”故事有感
  7. TFHE拓展:Programmable Bootstrapping
  8. 大额现金方式出借款项不宜不经审查直接以民事调解书
  9. 一篇合格的新闻稿由哪5部分构成?
  10. 缓冲区溢出(栈溢出)实验 之 JMP ESP