hdu1548
来源:互联网 发布:linux 关闭防火墙命令 编辑:程序博客网 时间:2024/05/29 19:25
#include<cstdio>#include<cstring>#include<cmath>#include<iostream>#include<algorithm>#include<queue>using namespace std;int s[205];int vis[205];int n,a,b;struct node{int x;//当前层数 int step;//按的次数 };int bfs(){queue<node>q;node c,next;c.x=a;c.step=0;vis[c.x]=1;int i;q.push(c);while(!q.empty()){c=q.front();q.pop();if(c.x==b)return c.step;next=c;next.x=next.x+s[next.x];if((vis[next.x]==0)&&(next.x>0)&&(next.x<=n)){vis[next.x]=1;next.step++;q.push(next);}next=c;next.x=next.x-s[next.x];if((vis[next.x]==0)&&(next.x>0)&&(next.x<=n)){vis[next.x]=1;next.step++;q.push(next);}}return -1; }int main(){while(scanf("%d",&n)!=EOF){if(n==0)break;scanf("%d%d",&a,&b);int i;memset(vis,0,sizeof(vis));for(i=1;i<=n;i++){scanf("%d",&s[i]);}printf("%d\n",bfs());}return 0;}
阅读全文
0 0
- hdu1548
- hdu1548
- hdu1548
- hdu1548
- hdu1548
- hdu1548
- HDU1548
- hdu1548
- hdu1548
- hdu1548
- HDU1548 BFS
- HDU1548(搜索)
- hdu1548(BFS)
- hdu1548 A strange lift
- HDU1548 A strange lift
- HDU1548 A strange lift
- hdu1548 A strange lift
- HDU1548---A strange lift
- 杨白劳外传
- 使用HTML语言和CSS开发商业站点_利用CSS3制作网页动画
- HDU 4010 Query on The Trees 点权LCT
- codevs1098 均分纸牌
- Qt4.8.5 VS2010 Visual Assist
- hdu1548
- [Python]网络数据采集概述(3)—穿越网页表单、登录窗口进行采集
- 冒泡排序
- 一句SQL完成动态分级查询
- 一次完整的http请求过程
- iOS automaticallyAdjustsScrollViewInsets(自动调整滚动视图)使用
- Json解析网络获取Viewpager图片glide下载图片
- 古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子对数为多少?
- 生产报表的自动化实现方案