HUD-1548
A strange lift
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 24630 Accepted Submission(s): 8898Problem DescriptionThere 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"?InputThe 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.OutputFor 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 Input5 1 53 3 1 2 50Sample Output3
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的更多相关文章
- 如何用Unity GUI制作HUD
若知其所以然,自然知其然. HUD是指平视显示器,就是套在脸上,和你的眼睛固定在一起,HUD的意思就是界面咯,一般我们说HUD特指把3D空间中的界面的某些信息(比如血条,伤害之类)的贴在界面上,对应3 ...
- xamarin UWP平台下 HUD 自定义弹窗
在我的上一篇博客中我写了一个在xamarin的UWP平台下的自定义弹窗控件.在上篇文章中介绍了一种弹窗的写法,但在实际应用中发现了该方法的不足: 1.当弹窗出现后,我们拖动整个窗口大小的时候,弹窗的窗 ...
- xamarin UWP设置HUD加载功能
使用xamarin开发的时候经常用到加载HUD功能,就是我们常见的一个加载中的动作,Android 下使用 AndHUD , iOS 下使用 BTProgressHUD, 这两个在在 NuGet 上都 ...
- OSG中的HUD
OSG中的HUD 所谓HUD节点,说白了就是无论三维场景中的内容怎么改变,它都能在屏幕上固定位置显示的节点. 实现要点: 关闭光照,不受场景光照影响,所有内容以同一亮度显示 关闭深度测试 调整渲染顺序 ...
- hdu 1548 楼梯 bfs或最短路 dijkstra
http://acm.hdu.edu.cn/showproblem.php?pid=1548 Online Judge Online Exercise Online Teaching Online C ...
- 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 ...
- 三分 --- CSU 1548: Design road
Design road Problem's Link: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1548 Mean: 目的:从(0,0)到 ...
- iOS之UI--指示器HUD的创建和设置
指示器的创建和设置 渐变动画 描述: 使用label就能制作指示器,原理:就是让label以动画的形式慢慢显示和消失 最好是半透明的 指示器有时候也被称为:HUD,遮盖,蒙版 思路步骤: 1.先在st ...
- NGUI:HUD Text(头顶伤害漂浮文字)
HUD Text 很早之前就有闻于NGUI中的HUD Text插件,今天得以尝试,看了会儿官方的文档,楞是没给看明白,官方的ReadMe.txt写的使用方法如下: 官网Usage 1. Attach ...
- POJ 1548 (二分图+最小路径覆盖)
题目链接:http://poj.org/problem?id=1548 题目大意:给出一张地图上的垃圾,以及一堆机器人.每个机器人可以从左->右,上->下.走完就废.问最少派出多少个机器人 ...
随机推荐
- qemu-kvm编译错误
今天编译了下qemu-kvm,死活编不过,错误信息如下: CC block/qcow2-snapshot.oIn file included from ./qemu-common.h:6:0, ...
- ecshop 国付宝支付接口
function get_code($order, $payment){ $version = '2.2'; $charset = '1'; $language = '1'; $signType = ...
- Python使用Mysql过程中一些错误
Python使用Mysql过程中一些错误 ssh登录远程服务器 ssh ubuntu@xxx.xxx.xx.xx 第一:ubuntu终端中登录Mysql mysql -uroot -p 然后输入密码即 ...
- 计算IMEI号的校验位
计算IMEI号的校验位 移动设备国际识别码(IMEI:International Mobile Equipment Identification Number)是差别移动设备的标志,具有唯一性,贴在手 ...
- MVC——分页
添加类PageBar.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; ...
- 对ShortCut和TWMKey的研究
TWMKey = packed record Msg: Cardinal; CharCode: Word; Unused: Word; KeyData: Longint; Result: Longin ...
- Linux就该这么学--命令集合8(命令行通配符)
1.查看sda开头的所有设备文件: ls /dev/sda* 2.查看sda后面只有一个字符的设备文件: ls /dev/sda? 3.查看sda后面包含0-9数字的设备文件: ls /dev/sda ...
- Java HotSpot(TM) 64-Bit Server VM warning: Insufficient space for shared memory file...
Java HotSpot(TM) 64-Bit Server VM warning: Insufficient space for shared memory file: 把tomcat中的日志删除, ...
- linux环境下远程访问ftp
sftp ftpuser@127.0.0.1 使用sftp命令 ftpuser是用户名 127.0.0.1是目标ip 亲测好使.
- github多用户提交错误Permission to repo denied to
背景:同一台电脑的public key同时添加到了github的两个账户,导致user1的仓库没法正常提交. 解决办法:为两个账户分别配置ssh key,配置~/.ssh/config文件(windo ...