HDU 2579 Dating with girls(2)
2012-02-11 21:13
302 查看
http://acm.hdu.edu.cn/showproblem.php?pid=2579
BFS
View Code
BFS
View Code
#include <cstdio> #include <cstring> #include <queue> using namespace std; const int N=110; const int dx[4]={0,1,0,-1}; const int dy[4]={1,0,-1,0}; char maze ; int vis [15]; int n,m,k; struct sta { int x,y,dis; }; queue<sta> q; int bfs(int x,int y) { while (!q.empty()) q.pop(); sta u={x,y,0}; vis[x][y][0]=1; q.push(u); while (!q.empty()) { u=q.front(); q.pop(); int x,y,d,nx,ny,dis; x=u.x; y=u.y; dis=u.dis+1; for (d=0;d<4;d++) { nx=x+dx[d]; ny=y+dy[d]; int bol1=vis[nx][ny][dis%k]; int bol2=!maze[nx][ny]; int bol3=maze[nx][ny]=='#' && dis%k!=0; if (bol1 || bol2 || bol3) continue; vis[nx][ny][dis%k]=1; sta v={nx,ny,dis}; q.push(v); if (maze[nx][ny]=='G') return dis; } } return -1; } int main() { int T; scanf("%d",&T); int i,j,x,y,ans; while (T--) { memset(vis,0,sizeof(vis)); memset(maze,0,sizeof(maze)); scanf("%d%d%d",&n,&m,&k); for (i=1;i<=n;i++) scanf("%s",maze[i]+1); for (i=1;i<=n;i++) for (j=1;j<=m;j++) if (maze[i][j]=='Y') {x=i; y=j;} ans=bfs(x,y); if (ans<0) printf("Please give me another chance!\n"); else printf("%d\n",ans); } return 0; }
相关文章推荐
- HDU 2579 Dating with girls(2) (BFS)
- HDU 2579 Dating with girls(2)
- Hdu 2579 Dating with girls(2) && hdu 2653 Waiting ten thousand years for Love【Bfs】
- HDU 2579 Dating with girls(2)
- HDU 2579 Dating with girls(2) (bfs)
- HDU 2579 Dating with girls(2) BFS+三重标记(标记时间)
- hdu 2579 Dating with girls(2) (BFS)
- HDU 2579 Dating with girls(2)
- HDU 2579 Dating with girls(2)
- HDU 2579 - Dating with girls(2)
- 【HDU】 2579 Dating with girls(2)(BFS,可重复)
- HDU 2579 Dating with girls(2)
- HDU 2579 Dating with girls(2) BFS
- hdu(2579) Dating with girls(2)
- hdu 2579 Dating with girls(2)【bfs】
- HDU 杭电2579 Dating with girls(2) 【BFS】
- hdu 2579 Dating with girls(2)
- HDU 2579 Dating with girls(2) BFS 余数判重
- hdu 2579 Dating with girls(2)【BFS+全文翻译】
- hdu 2579 Dating with girls(2) (bfs)