啊哈迷宫bfs解决方法
来源:互联网 发布:阿里云系统看电视 编辑:程序博客网 时间:2024/06/06 04:14
代码如下,忘记的时候回看啊哈算法bfs,感觉学了dfs看bfs轻松了很多
<span style="font-size:14px;">#include <iostream>#include <cstring>using namespace std;struct node{ int x; int y; int s;};struct node que[2501];int n,m,startx,starty,x,y,count_;int map[51][51];int visit[51][51];int next_[4][2]={{0,1},{1,0},{0,-1},{-1,0}};int main(){ int i,j,head=1,tail=1,flag=0,tx,ty; cin>>n>>m; for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { cin>>map[i][j]; } } cin>>startx>>starty>>x>>y; memset(visit, 0, sizeof(visit)); que[tail].x=startx; que[tail].y=starty; que[tail].s=0; tail++; visit[startx][starty]=1; while(head<tail) { for(i=0;i<4;i++) { /**/ tx=que[head].x+next_[i][0]; ty=que[head].y+next_[i][1]; if(tx<1 || tx >n || ty<1 || ty>m) continue; if(map[tx][ty]==0 && visit[tx][ty]==0) { /**/ visit[tx][ty]=1; que[tail].x=tx; que[tail].y=ty; que[tail].s=que[head].s+1; tail++; } if(tx==x && ty==y) { flag=1; break; } } if(flag==1) { break; } head++; } cout<<que[tail-1].s; return 0; }</span>
0 0
- 啊哈迷宫bfs解决方法
- BFS~~~迷宫
- BFS(迷宫)
- 迷宫-BFS
- BFS------迷宫
- 迷宫-BFS
- 啊哈炸弹人(dfs bfs)
- 啊哈报道探险(基础bfs)
- hdu1728 逃离迷宫(bfs)
- POJ3984 迷宫问题 BFS
- 经典迷宫问题BFS
- 迷宫问题 bfs
- 迷宫问题BFS暴搜
- BFS走迷宫
- BFS | 3984 | 迷宫问题
- HDU1728:逃离迷宫(BFS)
- hncu1102:迷宫问题(BFS)
- POJ3984 迷宫问题 BFS
- PAT乙级1019
- 3min初识ListView(6)-数组适配器介绍
- MongoDB 简介
- 工具
- vijos P1099虫食算【搜索
- 啊哈迷宫bfs解决方法
- Backbone View 之间通信的三种方式
- hdu 5927 Auxiliary Set
- (Canada Cup 2016 C) Hidden Word
- 旅行 {倍增水题请享用}
- Win7下的内置FTP组件的设置详解
- matplotlib-legend()
- ATSAMV7Xult板卡调试Nuttx系统----NuttX系统以太网卡的调试
- 找出最长数字子串,并指出开始位置