http://acm.hdu.edu.cn/showproblem.php?pid=1548

Online Judge Online Exercise Online Teaching Online Contests Exercise Author
F.A.Q
Hand In Hand
Online Acmers
Forum |Discuss
Statistical Charts
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
Virtual Contests
  DIY |Web-DIY beta
Recent Contests
 

A strange lift

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 15139    Accepted Submission(s): 5724

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 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
 
Recommend
8600   |   We have carefully selected several similar problems for you:  1385 1242 1142 1217 2544 
 

Statistic | Submit | Discuss | Note

Home | Top Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2015 HDU ACM Team. All Rights Reserved.
Designer & DeveloperWang Rongtao LinLe GaoJie GanLu
Total 0.003000(s) query 5, Server time : 2015-07-20 17:20:12, Gzip enabled
Administration

hdu 1548 楼梯 bfs或最短路 dijkstra的更多相关文章

  1. HDU 1548 A strange lift(最短路&&bfs)

    A strange lift Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  2. hdu 1548 简单BFS

    题意:坐电梯,每次可以选着上下,对应移动的楼层是Ki,问从起点到终点最少要按几次. AC代码: #include<cstdio> #include<cstring> #incl ...

  3. hdu 1548 简单bfs。。。

    由于题目过水.. 我就在这里把bfs的模板写一些吧.. bfs的思想是利用队列的特性 对树的每一层先遍历 每一次访问时取出队首 然后排出~ #include<queue>void bfs( ...

  4. cogs 364. [HDU 1548] 奇怪的电梯 Dijkstra

    364. [HDU 1548] 奇怪的电梯 ★   输入文件:lift.in   输出文件:lift.out   简单对比时间限制:1 s   内存限制:128 MB [问题描述] 呵呵,有一天我做了 ...

  5. hdu 2544 最短路 Dijkstra

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2544 题目分析:比较简单的最短路算法应用.题目告知起点与终点的位置,以及各路口之间路径到达所需的时间, ...

  6. 图-用DFS求连通块- UVa 1103和用BFS求最短路-UVa816。

    这道题目甚长, 代码也是甚长, 但是思路却不是太难.然而有好多代码实现的细节, 确是十分的巧妙. 对代码阅读能力, 代码理解能力, 代码实现能力, 代码实现技巧, DFS方法都大有裨益, 敬请有兴趣者 ...

  7. POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)

    POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...

  8. 算法学习笔记(三) 最短路 Dijkstra 和 Floyd 算法

    图论中一个经典问题就是求最短路.最为基础和最为经典的算法莫过于 Dijkstra 和 Floyd 算法,一个是贪心算法,一个是动态规划.这也是算法中的两大经典代表.用一个简单图在纸上一步一步演算,也是 ...

  9. HDU 1142 A Walk Through the Forest(dijkstra+记忆化DFS)

    题意: 给你一个图,找最短路.但是有个非一般的的条件:如果a,b之间有路,且你选择要走这条路,那么必须保证a到终点的所有路都小于b到终点的一条路.问满足这样的路径条数 有多少,噶呜~~题意是搜了解题报 ...

随机推荐

  1. HDOJ 1512 几乎模板的左偏树

    题目大意:有n个猴子.每个猴子有一个力量值,力量值越大表示这个猴子打架越厉害.如果2个猴子不认识,他们就会找他们认识的猴子中力量最大的出来单挑,单挑不论输赢,单挑的2个猴子力量值减半,这2拨猴子就都认 ...

  2. 奔小康赚大钱 hdu 2255( KM )

    http://acm.split.hdu.edu.cn/showproblem.php?pid=2255 带权匹配问题: #include <stdio.h> #include <a ...

  3. Maven 自动部署

    自动部署到Tomcat Maven 3.2.5 JDK 1.7 Tomcat 7 首先在Tomcat里配置deploy的用户(tomcat根目录/conf/tomcat-users.xml): < ...

  4. sqlserver中,查看某个函数的调用情况

    今天想在sqlserver中看看自己写的函数都被哪个函数或存储过程调用了,手工检查起来太慢了,于是在网上找一个快速的方法,分享一下. select * from sys.all_sql_modules ...

  5. STREAMS流机制

    STREAMS流机制 基本概念 STREAMS(流)是系统V提供的构造内核设备驱动程序和网络协议包的一种通用方法,对STREAMS进行讨论的目的是为了理解系统V的终端接口,I/O多路转接中poll(轮 ...

  6. gvim 配置Pydiction

    配置windows下gvim 的python关键字补全插件Pydiction 1.下载Pydiction 2.解压缩包,里面有after文件夹.complete-dict.pydiction.py 3 ...

  7. HighChats报表使用C#mvc导出本地图片

    最近工作使用了HighCharts,要用到保存成图片功能,但是是内部使用,不允许连接外网,于是就学习了下highcharts生成本地图片. highcharts有一个exporting.js来负责导出 ...

  8. ns3模拟无线Ad hoc 网络通信

    Ad hoc网络 Ad hoc网是一种多跳的.无中心的.自组织无线网络,又称为多跳网(Multi-hop Network).无基础设施网(Infrastructureless Network)或自组织 ...

  9. Appium客户端

    Appium版本:1.5.3 Xcode有两个版本:Xcode8.1   Xcode7.2.1 iOS10以下只能用Xcode7.2.1 iOS10及以上可以用Xcode8.1   1.Appium客 ...

  10. 用JS制作简易的可切换的年历,类似于选项卡

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 30.0px Consolas; color: #2b7ec3 } p.p2 { margin: 0.0px ...