hdu 1728 逃离迷宫 bfs
2011-12-22 17:59
501 查看
蛋疼,犯了2个错误
1.不能每遇到个点都把它四个方向的每个点都走一个(每个点入一次队列),这样要mle
2.不能把已经走过的点标记成‘*’,这样要wa
View Code
1.不能每遇到个点都把它四个方向的每个点都走一个(每个点入一次队列),这样要mle
2.不能把已经走过的点标记成‘*’,这样要wa
View Code
#include <stdio.h> #include <queue> using namespace std; struct node{ int x,y,cnt; }a; int n,m,ex,ey,k; char map[105][105]; int bfs() { int i,row,col,dir[4][2]={0,1,1,0,-1,0,0,-1}; queue<node> q; q.push(a); while (!q.empty()) { a=q.front();q.pop(); if(a.cnt==k+1)return 0; for (i=0;i<4;i++) { row=dir[i][0]+a.x; col=dir[i][1]+a.y; while (row>=0&&col>=0&&row<n&&col<m&&map[row][col]!='*') { if(row==ex-1&&col==ey-1)return 1; if(map[row][col]=='.') { map[row][col]='@'; node b; b.x=row,b.y=col,b.cnt=a.cnt+1; q.push(b); } row+=dir[i][0]; col+=dir[i][1]; } } } return 0; } int main() { int T,i,sx,sy; scanf("%d",&T); while (T--) { scanf("%d%d",&n,&m); for (i=0;i<n;i++)scanf("%s",map[i]); scanf("%d%d%d%d%d",&k,&sy,&sx,&ey,&ex); if(sy==ey&&sx==ex) { printf("yes\n"); continue; } map[sx-1][sy-1]='*'; a.x=sx-1,a.y=sy-1,a.cnt=0; if(bfs())printf("yes\n"); else printf("no\n"); } return 0; } /* 5 5 ..... ..... ....* ..... ..... 1 1 1 5 5 */
相关文章推荐
- HDU 1728逃离迷宫(DFS或者BFS)
- hdu 1728 逃离迷宫 bfs记步数
- hdu 1728 逃离迷宫 (论DFS思想在BFS中的应用)
- hdu 1728 逃离迷宫(BFS 有 限制条件,陷阱比较多)
- 搜索专题(DFS&&BFS&&剪枝)HDU 1728-逃离迷宫
- HDU 1728逃离迷宫(DFS或者BFS)
- hdu 1728 逃离迷宫(BFS)
- HDU 1728 逃离迷宫 单方向BFS 或者DFS加剪枝
- HDU1728 逃离迷宫 【BFS】
- HDU 1728 逃离迷宫 BFS
- hdu 1728 逃离迷宫 (bfs)
- hdu - 1728逃离迷宫 && hdu - 1175 连连看 (普通bfs)
- hdu 1728 逃离迷宫[简单bfs]
- hdu 1728 逃离迷宫 经典BFS
- HDU1728 逃离迷宫 【方向BFS】
- 逃离迷宫 HDU-1728 BFS深度搜索
- HDU 1728 逃离迷宫(BFS)
- HDU 1728 逃离迷宫(BFS)
- HDU 1728 逃离迷宫(BFS+DFS)
- HDU 1728 逃离迷宫 转向限制BFS