HDU 1728 逃离迷宫 BFS
2013-10-05 09:46
375 查看
看题传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1728
这题的x1,x2对应列,y1,
y2对应行 。。很邪恶
还要注意下标应该从1开始。。。。一时傻了调了半天。
还有前后坐标一样的时候。。。。贡献一次WA
同样的还是BFS的应用。
只不过是用一个step来标记目前转过的弯,每条路一路走到底。
这题的x1,x2对应列,y1,
y2对应行 。。很邪恶
还要注意下标应该从1开始。。。。一时傻了调了半天。
还有前后坐标一样的时候。。。。贡献一次WA
同样的还是BFS的应用。
只不过是用一个step来标记目前转过的弯,每条路一路走到底。
#include<iostream> #include<cstdio> #include<cstring> #include<queue> using namespace std; const int MAXN=100+10; int n,m,k; char maze[MAXN][MAXN]; bool vis[MAXN][MAXN]; const int dx[]={0,1,0,-1}; const int dy[]={-1,0,1,0}; struct site { int x,y; int step; site(int i=-1,int j=-1,int s=-1){x=i;y=j;step=s;} }start,en; bool bfs() { if(start.x==en.x && start.y==en.y) return true; memset(vis,0,sizeof(vis)); vis[start.x][start.y]=true; start.step=-1; queue<site> q; q.push(start); while(!q.empty()) { site temp=q.front(); q.pop(); for(int i=0;i<4;i++) { int nx=temp.x+dx[i]; int ny=temp.y+dy[i]; while(nx >=1 && ny >=1 && nx<=m && ny<=n && maze[nx][ny]=='.') { if(vis[nx][ny]==false) { q.push(site(nx,ny,temp.step+1)); vis[nx][ny]=true; if(nx==en.x && ny==en.y && temp.step+1<=k) return true; } nx=nx+dx[i]; ny=ny+dy[i]; } } } return false; } int main() { int t; scanf("%d",&t); while(t--) { scanf("%d%d",&m,&n); for(int i=1;i<=m;i++) scanf("%s",maze[i]+1); scanf("%d%d%d%d%d",&k,&start.y,&start.x,&en.y,&en.x); if(bfs()) printf("yes\n"); else printf("no\n"); } }
相关文章推荐
- 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+DFS)
- HDU 1728 逃离迷宫(BFS+转弯次数+转弯方向)
- hdu 1728 BFS 逃离迷宫 值得注意
- HDU 1728 逃离迷宫(BFS)
- HDU 1728 逃离迷宫(BFS)
- HDU 1728 逃离迷宫 bfs 限制k次转弯
- HDU 1728 逃离迷宫 转向限制BFS
- hdu 1728 逃离迷宫 (BFS)
- HDU 1728 逃离迷宫【BFS】
- HDU 1728 逃离迷宫(BFS)
- hdu 1728 逃离迷宫 BFS
- HDU 1728 逃离迷宫【bfs】