HDU1728 逃离迷宫
2017-02-16 23:37
253 查看
the question is here http://acm.hdu.edu.cn/showproblem.php?pid=1728
I work so hard to find a way to cut edges.I failed at last.So I learn that from other people.I realize that cuting-edges is not a easy work,but requiring hard work and learn.And If I give up before learn nothing.All the effort is gone.So this question need to book the nubers of turns that the girl made and cut depend on different sutution.
I work so hard to find a way to cut edges.I failed at last.So I learn that from other people.I realize that cuting-edges is not a easy work,but requiring hard work and learn.And If I give up before learn nothing.All the effort is gone.So this question need to book the nubers of turns that the girl made and cut depend on different sutution.
#include <bits/stdc++.h> #define inf 0x3fffffff using namespace std; const int MAXN=105; char m[MAXN][MAXN]; int turn[MAXN][MAXN]; int flag=0; int dx[4]= {-1,0,1,0}; int dy[4]= {0,1,0,-1}; int N,M,k; int tx,ty; /* 1 5 5 ...** *.**. ..... ..... *.... 2 1 1 1 3 */ void dfs(int x,int y,int dir) { if(x==tx&&y==ty) { if(turn[x][y]<=k) { flag=1; } return; } if(turn[x][y]>k) return; if(turn[x][y]==k && x!=tx && y!=ty) return; for(int i=0; i<4; i++) { int xx=x+dx[i]; int yy=y+dy[i]; if(xx<0||xx>=N||yy<0||yy>=M) continue; if(m[xx][yy]=='*'||turn[xx][yy]<turn[x][y]) continue; if(dir!=-1&&dir!=i&&turn[xx][yy]<turn[x][y]+1) continue; turn[xx][yy]=turn[x][y]; if(dir!=-1&&i!=dir) { turn[xx][yy]+=1; } dfs(xx,yy,i); if(flag==1) { return; } } } int main() { int t; cin>>t; while(t--) { cin>>N>>M; for(int i=0; i<N; i++) { scanf("%s",m[i]); } int sx,sy; cin>>k>>sy>>sx>>ty>>tx; sx--;sy--;tx--;ty--; for(int i=0; i<N; i++) { for(int j=0;j<M; j++) { turn[i][j]=inf; } } flag=0; turn[sx][sy]=0; dfs(sx,sy,-1); if(flag==1) { cout<<"yes"<<endl; } else { cout<<"no"<<endl; } } return 0; }
相关文章推荐
- HDU 1728 逃离迷宫 (bfs+一条路走到底思想)
- HDU 1728 逃离迷宫【bfs】
- HDU 1728 逃离迷宫(DFS经典题,比赛手残写废题)
- 逃离迷宫 HDU-1728 BFS深度搜索
- HDU 1728 逃离迷宫(dfs或bfs+剪枝)
- HDU1728--逃离迷宫
- HDU 1728 逃离迷宫
- hdu 1728 逃离迷宫(dFS+优先队列)
- HDU 1728 逃离迷宫
- HDU 1728 逃离迷宫 (搜索)
- [HDU]1728逃离迷宫
- hdu 1728 逃离迷宫(BFS 有 限制条件,陷阱比较多)
- hdu1728 逃离迷宫 bfs
- HDU 1728 逃离迷宫(BFS)
- HDU 1728 逃离迷宫 单方向BFS 或者DFS加剪枝
- HDU 1728 逃离迷宫
- hdu(1728)逃离迷宫
- HDU 1728 逃离迷宫 BFS(加转弯数)
- hdu 1728 逃离迷宫
- 【hdu 1728】 逃离迷宫 广搜(最少拐弯次数)