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. Android 5.0状态栏和导航栏

    Material Design推出之后,app中也開始沿用这样的风格 今天来说一下状态栏颜色设置,在4.4的时候推出了透明状态栏和导航栏.在不使用第三方库的情况下,4.4还是没有全然解决存在actio ...

  2. 我的Android进阶之旅------&gt;Android中android:windowSoftInputMode的使用方法

    面试题:怎样在显示某个Activity时马上弹出软键盘? 答案:在AndroidManifest.xml文件里设置<activity>标签的android:windowSoftInputM ...

  3. “checkbox”和“select”对象在javascript和jquery的操作差异做了整理

    checkbox checkbox在javascript和jquery中选中和取消的方法 Javascript: document.getElementById("myCheck" ...

  4. MVC3 类型 System.Web.Mvc.ModelClientValidationRule 同时存在

    用文本编辑器打开  工程名称 .csproj 找到 1. <Reference Include="System.Web.WebPages" /> 2. <Refe ...

  5. cpio

    1 压缩 -o,生成cpio格式的归档文件.从标准输入获取文件名列表. 2 解压 -i,对cpio格式的归档文件进行解压,生成单个的文件. 3 --null 从标准输入获取的文件名列表为"\ ...

  6. 活动推荐 | 听说 PHP 是最好的语言 - 和 OneAPM 一起參与上海 PHPCon 技术盛宴吧

    2015年7月11日,第三届 PHP 大会就要和各位 PHPer 正式见面了.本年度,由 Think 技术社区主办,OneAPM 赞助的 PHPCon2015 是为全部热爱技术的 PHPer 提供的最 ...

  7. git基本操作---持续更新(2017-08-11)

    git 强制push $ git push -u origin master -f 查看本地标签 $ git tag 打标签并添加备注 $ git tag 20170811 -m"图片保存多 ...

  8. SAP bseg 使用注意点:1.不要使用;2.有主键再用,

    粗表-簇表 cluster-table BSEGRFBLG 池表 pool-table 我記的沒錯的話,在21天學會ABAP中有一節是專門在講Cluster table,另外在 www.sapfans ...

  9. 【操作系统】使用BCD工具安装Ubuntu操作系统

    Ubuntu14.04作为目前最新版本的ubuntu系统,相信很多人都想在自己的电脑上安装一下,然而系统的安装方法各式各样,U盘法.grub引导法等等,本文将介绍在win7系统下用easyBCD软件建 ...

  10. [数据挖掘课程笔记]关联规则挖掘 - Apriori算法

    两种度量: 支持度(support)  support(A→B) = count(AUB)/N (N是数据库中记录的条数) 自信度(confidence)confidence(A→B) = count ...