HDU1548(楼梯问题bfs)
#include"cstdio"
#include"queue"
#include"cstring"
using namespace std;
const int MAXN=;
typedef pair<int,int> P;
int N,A,B;
int K[MAXN];
int vis[MAXN];
int bfs()
{
queue<P> que;
que.push(P(,A));
vis[A]=;
while(!que.empty())
{
P now=que.front();que.pop();
if(now.second==B)
{
return now.first;
}
for(int i=-;i<=;i++)
{
int next=now.second+K[now.second]*i;
if(<next&&next<=N&&!vis[next])
{
vis[next]=;
que.push(P(now.first+,next));
}
}
}
return -;
}
int main()
{
while(scanf("%d",&N)!=EOF&&N!=)
{
scanf("%d %d",&A,&B);
for(int i=;i<=N;i++)
{
scanf("%d",&K[i]);
}
memset(vis,,sizeof(vis));
printf("%d\n",bfs());
}
return ;
}
HDU1548(楼梯问题bfs)的更多相关文章
- HDU 1180 诡异的楼梯(BFS)
诡异的楼梯 Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status ...
- 诡异的楼梯(bfs)hdu1180
诡异的楼梯 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submiss ...
- HDU1180:诡异的楼梯(bfs+优先队列)
http://acm.hdu.edu.cn/showproblem.php?pid=1180 Problem Description Hogwarts正式开学以后,Harry发现在Hogwarts里, ...
- hdu 1180:诡异的楼梯(BFS广搜)
诡异的楼梯 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Subm ...
- HDU 1180 诡异的楼梯【BFS/楼梯随时间变化】
诡异的楼梯 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Submis ...
- hdoj1180 诡异的楼梯(bfs+奇偶判断)
手癌!日常手癌!被自己气死! #include<iostream> #include<cstring> #include<queue> #include<al ...
- hdu - 1180 诡异的楼梯 (bfs+优先队列)
http://acm.hdu.edu.cn/showproblem.php?pid=1180 注意点就是楼梯是在harry移动完之后才会改变方向,那么只要统计到达这个点时间奇偶性,就可以知道当前楼梯是 ...
- hdu 1180 诡异的楼梯 (bfs)
诡异的楼梯 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Sub ...
- hdu 1180诡异的楼梯(bfs)
诡异的楼梯 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) Total Submis ...
随机推荐
- 【python】-- 列表
Python中最基本的数据结构.序列中的每个元素都分配一个数字 - 它的位置,或索引,第一个索引是0,第二个索引是1,依此类推 列表 1.定义列表,取出列表中的值 names = [] #定义空列表 ...
- centos6下nginx配置php可用
先查看下所有服务的状态,看看php-fpm有没有正在运行 [root@centos64 html]# service --status-all php-fpm (pid 3568) 正在运行... ...
- python cookbook第三版学习笔记十九:未包装的函数添加参数
比如有下面如下的代码,每个函数都需要判断debug的是否为True,而默认的debug为False def a(x,debug=False): if debug: print('calling a') ...
- Js拼接html并给onclick传多个参数
return '<a id="" class="ace_button" href="#" onclick="showItem ...
- 2.5链表 链式A+B
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAowAAAGpCAIAAACI2PCZAAAgAElEQVR4nO2d3YsdSX6m++/wXf8Fxu ...
- VIM YCM 插件安装问题记录
参考:https://github.com/yangyangwithgnu/use_vim_as_ide https://github.com/Valloric/YouCompleteMe 根据 ht ...
- UVALive - 6257 K - Chemist's vows 【DFS】【BFS】【DP】
题目链接 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- Kattis - triangle 【数学】
题意 求第N个迭代三角形 中 所有黑色三角形的周长的整数部分的位数 思路 该三角形的周长是 3^(n + 1)/ 2 ^ (n) 然后 可以用 long double 存下来 再求位数 就可以 AC ...
- vary的用法
对于vary的用法,网上有许多种说法,云里雾里的,在此仅阐述一下本人的一些理解,首先是官方解释: Vary头域值指定了一些请求头域,这些请求头域用来决定: 当缓存中存在一个响应,并且该缓存没有过期失效 ...
- Vim 替换命令
一,":substitute"的使用 :substitute 命令可以对一个指定范围的区域执行替换操作,可以简写为:s ,它的通用形式如下: :[range]substitute/ ...