hdu 1072 Nightmare
来源:互联网 发布:郑州java培训多少钱 编辑:程序博客网 时间:2024/05/14 07:54
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1072
//这里不能标记路径,所以不能深搜,用深搜会成死循环//广搜,无线搜索下去,当收到的时候,一定是个最短的距离,#include<stdio.h>#include<string.h>#include<queue>using namespace std;int map[8][8];int n,m,sx,sy,tx,ty;int dx[]={1,0,-1,0};int dy[]={0,1,0,-1};struct node{ int x,y,step,Time;}star;void bfs(){ queue<node> q; q.push(star); node p1,p2; int i; while(!q.empty()) { p1=q.front(); q.pop(); for(i=0;i<4;i++) { p2.x=p1.x+dx[i];p2.y=p1.y+dy[i]; p2.step=p1.step+1;p2.Time=p1.Time-1; if(p2.x>=0&&p2.y>=0&&p2.y<m&&p2.x<n&&p2.Time>0&&map[p2.x][p2.y]) { if(map[p2.x][p2.y]==4) {p2.Time=6;map[p2.x][p2.y]=0;} if(map[p2.x][p2.y]==3) {printf("%d\n",p2.step);return;}//上面时间大于0才执行这里,所以这里时间不要再大于0了 q.push(p2); } } } printf("-1\n");}int main(){ int i,j,T; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); for(i=0;i<n;i++) for(j=0;j<m;j++) { scanf("%d",&map[i][j]); if(map[i][j]==2) { star.x=i; star.y=j; star.step=0; star.Time=6; } } bfs(); } return 0;}
- HDU 1072 Nightmare
- BFS hdu 1072 Nightmare
- HDU 1072 Nightmare BFS
- HDU 1072 Nightmare
- hdu 1072 Nightmare BFS
- hdu Nightmare 1072
- Hdu 1072 - Nightmare
- hdu 1072 Nightmare bfs
- HDU-1072:Nightmare
- hdu 1072 Nightmare
- HDU 1072 Nightmare
- HDU-1072-Nightmare
- hdu 1072 Nightmare
- HDU 1072 Nightmare
- Nightmare hdu 1072
- hdu 1072 Nightmare
- hdu 1072 Nightmare
- HDU 1072 Nightmare(搜索)
- 【游戏宅】期待明年的大作啊
- HTML颜色关键词
- Asp.net课堂笔记
- 点点细雨的项目日记(一) 需…
- 点点细雨的项目日记(二) 数…
- hdu 1072 Nightmare
- 点点细雨的项目日记(三) 三…
- 点点细雨的项目日记(四) 权…
- 点点细雨的项目日记(五) 页…
- 点点细雨的项目日记(六) 关…
- 呵呵,开始学习html5
- csdn论坛谈加班
- 中关村
- 什么是变量?