hdu 1072 Nightmare (BFS)
来源:互联网 发布:淘宝erp 编辑:程序博客网 时间:2024/05/10 10:01
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1072
/*走过点可以再走,只要第二次走的时候,剩余时间大于之前走的那次。*/#include<stdio.h>#include<string.h>#include<queue>#include<algorithm>using namespace std;struct node{ int x,y,t,time;//};int map[9][9],vis[9][9],t,n,m;//vis存人经过这个点时的最大剩余时间int dx[]={1,-1,0,0};int dy[]={0,0,1,-1};void bfs(node vs,node vt){ queue<node>q; q.push(vs); int flag=-1; node vn,vw; while(!q.empty()) { vn=q.front(); q.pop(); if(vn.x==vt.x&&vn.y==vt.y&&vn.t>0)//在爆炸之前找到了出口 { flag=vn.time; break; } if(vn.t<=0)//爆炸了 { break; } else { int i; for(i=0;i<4;i++) { vw.x=vn.x+dx[i]; vw.y=vn.y+dy[i]; vw.t=vn.t-1; vw.time=vn.time+1; if(vw.x>=1&&vw.x<=n&&vw.y>=1&&vw.y<=m&&map[vw.x][vw.y]!=0&&vw.t>vis[vw.x][vw.y])//剩余时间要大于之前走的那次 { if(map[vw.x][vw.y]!=4) { q.push(vw);vis[vw.x][vw.y]=vw.t; } else { vw.t=6; q.push(vw); vis[vw.x][vw.y]=6; } } } } } printf("%d\n",flag);}int main(){ scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); int i,j; node vs,vt; for(i=1;i<=n;i++) for(j=1;j<=m;j++) { scanf("%d",&map[i][j]); if(map[i][j]==2) { vs.t=6; vs.x=i;vs.y=j; vs.time=0; } if(map[i][j]==3) { vt.x=i; vt.y=j; } } memset(vis,0,sizeof(vis)); bfs(vs,vt); } return 0;}
- hdu 1072 Nightmare (bfs)
- hdu 1072 Nightmare (BFS)
- hdu 1072 Nightmare bfs()
- hdu 1072Nightmare(bfs)
- HDU-#1072 Nightmare(BFS)
- HDU 1072:Nightmare(BFS)
- hdu 1072 Nightmare(bfs)
- hdu 1072 Nightmare(bfs)
- hdu-1072-Nightmare(bfs)
- HDU 1072 Nightmare(BFS)
- hdu 1072 Nightmare (BFS)
- HDU-1072 Nightmare(bfs)
- BFS hdu 1072 Nightmare
- HDU 1072 Nightmare BFS
- hdu 1072 Nightmare BFS
- hdu 1072 Nightmare bfs
- Hdu 1072 Nightmare[Bfs]
- hdu 1072 Nightmare--bfs
- C++ 声明和定义辨析
- 终极母函数 hdu 1079
- android常用代码小结
- 字符串处理你(在字符串前加符号)
- Shell脚本编程的常识
- hdu 1072 Nightmare (BFS)
- 致诸位程序员
- 项目4-变量的交换
- Missionaries and Cannibals problem breadth first search implementation
- struts1 action线程安全问题
- 给IPHONE程序提交 图标
- 豌豆夹等工具会导致start adb失败,android模拟器无法启动
- 补码的本质(上)
- CAGradientLayer简介