HDU_1548_AStrangeLift
来源:互联网 发布:作死的员工知乎 编辑:程序博客网 时间:2024/06/08 17:29
bfs即可每个楼梯有两种情况
#include <iostream>#include <stdio.h>#include <queue>#include <string.h>using namespace std;const int M=205;int fl[M];int isu[M];queue<int>re;void clearu() //清空{ for(int i=0;i<M;i++) //这里的范围记得改; { isu[i]=0; }}void bfs(int sx,int ex,int n){ while(!re.empty()) re.pop(); re.push(sx); isu[sx]=1; while(!re.empty()) { int t=re.front(); re.pop(); int tmp=t+fl[t]; //常用的表达式设为变量 if(1<=tmp&&tmp<=n&&!isu[tmp]) { re.push(tmp); isu[tmp]=isu[t]+1; if(tmp==ex) return; } tmp=t-fl[t]; if(1<=tmp&&tmp<=n&&!isu[tmp]) { re.push(tmp); isu[tmp]=isu[t]+1; if(tmp==ex) return; } }}int main(){ int n; int a,b; while(scanf("%d",&n)!=EOF) { clearu(); if(!n) break; scanf("%d%d",&a,&b); for(int i=1;i<=n;i++) { scanf("%d",&fl[i]); } bfs(a,b,n); printf("%d\n",isu[b]-1); //涵盖了不可能的情况 } return 0;}
0 0
- HDU_1548_AStrangeLift
- 各种排序算法比较(1):稳定性
- 径向基神经网络(实例故障分类)
- 建造SAP Fiori部署
- Mysql 5.6安装笔记
- android jxl OOM内存溢出问题解决(适用大部分内存溢出)
- HDU_1548_AStrangeLift
- DMA和cache的一致性
- C++ 深入理解 虚继承、多重继承和直接继承
- 【小技巧】Android返回按钮的监听器
- getcher getch getched用法和缓冲区的概念
- 各种排序算法比较(2):时间复杂度,空间复杂度
- CSS 哪些属性默认会继承, 哪些不会继承
- tcpdump丢包问题解决方法
- Ubuntu修改apt-get镜像地址提高下载速度