A strange lift

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

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

BFS

附AC代码:

 #include<bits/stdc++.h>
using namespace std; int n,s,e;
int ss[],vis[]; struct node{
int x,step;
}; int bfs(){
queue<node> Q;
node a,next;
a.x=s;
a.step=;
vis[s]=;
Q.push(a);
while(!Q.empty()){
a=Q.front();
Q.pop();
if(a.x==e)
return a.step;
for(int i=-;i<=;i+=){
next=a;
next.x+=i*ss[next.x];
if(next.x<=||next.x>n||vis[next.x])
continue;
vis[next.x]=;
next.step++;
Q.push(next);
}
}
return -;
} int main(){
while(cin>>n&&n){
cin>>s>>e;
for(int i=;i<=n;i++){
cin>>ss[i];
}
memset(vis,,sizeof(vis));
cout<<bfs()<<endl;
}
return ;
}

HUD-1548的更多相关文章

  1. 如何用Unity GUI制作HUD

    若知其所以然,自然知其然. HUD是指平视显示器,就是套在脸上,和你的眼睛固定在一起,HUD的意思就是界面咯,一般我们说HUD特指把3D空间中的界面的某些信息(比如血条,伤害之类)的贴在界面上,对应3 ...

  2. xamarin UWP平台下 HUD 自定义弹窗

    在我的上一篇博客中我写了一个在xamarin的UWP平台下的自定义弹窗控件.在上篇文章中介绍了一种弹窗的写法,但在实际应用中发现了该方法的不足: 1.当弹窗出现后,我们拖动整个窗口大小的时候,弹窗的窗 ...

  3. xamarin UWP设置HUD加载功能

    使用xamarin开发的时候经常用到加载HUD功能,就是我们常见的一个加载中的动作,Android 下使用 AndHUD , iOS 下使用 BTProgressHUD, 这两个在在 NuGet 上都 ...

  4. OSG中的HUD

    OSG中的HUD 所谓HUD节点,说白了就是无论三维场景中的内容怎么改变,它都能在屏幕上固定位置显示的节点. 实现要点: 关闭光照,不受场景光照影响,所有内容以同一亮度显示 关闭深度测试 调整渲染顺序 ...

  5. hdu 1548 楼梯 bfs或最短路 dijkstra

    http://acm.hdu.edu.cn/showproblem.php?pid=1548 Online Judge Online Exercise Online Teaching Online C ...

  6. CREATE A ENERGY / HEALTH BAR HUD

    Now then, let's get started. 1. Open the Play scene which you had created in the previous post. If y ...

  7. 三分 --- CSU 1548: Design road

    Design road Problem's Link:   http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1548 Mean: 目的:从(0,0)到 ...

  8. iOS之UI--指示器HUD的创建和设置

    指示器的创建和设置 渐变动画 描述: 使用label就能制作指示器,原理:就是让label以动画的形式慢慢显示和消失 最好是半透明的 指示器有时候也被称为:HUD,遮盖,蒙版 思路步骤: 1.先在st ...

  9. NGUI:HUD Text(头顶伤害漂浮文字)

    HUD Text 很早之前就有闻于NGUI中的HUD Text插件,今天得以尝试,看了会儿官方的文档,楞是没给看明白,官方的ReadMe.txt写的使用方法如下: 官网Usage 1. Attach ...

  10. POJ 1548 (二分图+最小路径覆盖)

    题目链接:http://poj.org/problem?id=1548 题目大意:给出一张地图上的垃圾,以及一堆机器人.每个机器人可以从左->右,上->下.走完就废.问最少派出多少个机器人 ...

随机推荐

  1. Something about cache

    http://www.tyut.edu.cn/kecheng1/2008/site04/courseware/chapter5/5.5.htm 5.5 高速缓冲存储器cache 随着CPU时钟速率的不 ...

  2. Matlab princomp函数浅析

    matlab中的princomp函数主要是实现主成分分析的功能,有1一个输入参数,4个返回参数,形式如下: [coef, score, latent, t2] = princomp(X) 输入: X为 ...

  3. UVa11234 表达式

    题意:题目意思是给出后缀表达式.能够通过栈来计算表达式的值,即转化为中缀表达式. 然后如果如今不用栈.而是用队列来操作.即每遇到一操作符时.进行两次pop和一次push.(这里注意,先pop出来的作为 ...

  4. Android添加系统级顶层窗口 和 WindowManager添加view的动画问题

    当Dialog有编辑框时如果选择会弹菜单窗口就不要用 Context applicationContext = mainActivity.getApplicationContext(); AlertD ...

  5. python--软件规范和反射

    软件开发规范 写一个作业的时候,要将写的代码分开  bin文件夹里面第一个是start文件  核心代码都在core文件夹里面  文件core最好也是固定名字 BaseDir=os.path.dirna ...

  6. 浅析嵌入式C优化技巧

    嵌入式C语言优化小技巧 1 概述 嵌入式系统是指完毕一种或几种特定功能的计算机系统,具有自己主动化程度高,响应速度快等长处,眼下已广泛应用于消费电子,工业控制等领域.嵌入式系统受其使用的硬件以及运行环 ...

  7. websotrom 2016.2 license Server

    license server” 输入:http://114.215.133.70:41017 仅供学习测试使用,支持正版.

  8. 微信小程序首页index.js获取不到app.js中动态设置的globalData的原因以及解决方法

    前段时间开发了一款微信小程序,运行了也几个月了,在index.js中的onLoad生命周期里获取app.js中onLaunch生命周期中在接口里动态设置的globalData一直没有问题,结果昨天就获 ...

  9. MySQL安装过程中出现“APPLY security settings错误”的解决方式

    ***********************************************声明*************************************************** ...

  10. android Material

    目前已经两个团队做了不错的翻译 http://design.1sters.com/ http://www.ui.cn/Material/ https://github.com/stormzhang/9 ...