hdoj 1072 Nightmare 广搜
来源:互联网 发布:淘宝店运营商靠谱吗 编辑:程序博客网 时间:2024/05/15 10:38
Nightmare(题目链接)
#include<istream>#include<algorithm>#include<queue>#include<cstdio>using namespace std;int t,n,m;int mat[10][10];int dir[4][2]={0,1,0,-1,1,0,-1,0};struct Node{ int x,y,ans,time;}s,t1,t2;void bfs() //广搜{ queue<Node>q; q.push(s); while(!q.empty()) { t1=q.front(); q.pop(); for(int i=0;i<4;i++) //走啊走 四处转悠 { t2.x=t1.x+dir[i][0]; t2.y=t1.y+dir[i][1]; t2.ans=t1.ans+1; t2.time=t1.time-1; if(t2.x>=0&&t2.x<n&&t2.y>=0&&t2.y<m&&mat[t2.x][t2.y]!=0&&t2.time>0) //不越界 地图值不为零 时间还有剩余 { if(mat[t2.x][t2.y]==3) //结束 { printf("%d\n",t2.ans); return ; } if(mat[t2.x][t2.y]==4) //重置时间 { t2.time=6; mat[t2.x][t2.y]=0; } q.push(t2); } } } printf("-1\n"); //没办法喽 输出-1 }int main(){ scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { scanf("%d",&mat[i][j]); if(mat[i][j]==2) { s.x=i; s.y=j; s.time=6; s.ans=0; } } } bfs(); } return 0;}
阅读全文
0 0
- hdoj 1072 Nightmare 广搜
- hdu 1072 Nightmare(广搜)
- HDU 1072 Nightmare(广搜)
- hdu 1072 Nightmare (广搜)
- hdu 1072 Nightmare (广搜)
- hdu1072 Nightmare 广搜
- 简单广搜:Nightmare
- Nightmare-HDU-广搜
- HDOJ 1072 Nightmare (bfs)
- HDOJ 1072 Nightmare
- HDOJ 1072 Nightmare
- HDOJ 1072 Nightmare bfs
- hdoj 1072 Nightmare
- hdoj 1072 Nightmare 【bfs】
- hdoj 1072 Nightmare
- HDOJ 1072 Nightmare
- hdoj-【1072 Nightmare】
- hdoj-1072Nightmare
- Matlab Tools for Network Analysis 网络分析工具包 (2006-2011)
- 初学opencv/基本操作
- 七、负载均衡-Ribbon 如何对负载均衡策略进行扩展
- Professional JS(try-catch续/Node/Document类型)
- RSA加解密应用
- hdoj 1072 Nightmare 广搜
- 猴子吃桃问题
- 常用 SQL Server 规范集锦
- JAVA面向对象易错习题详解
- hibernate学习笔记一
- spring整合hibernate出现HibernateException: Unable to get the default Bean Validation factory
- HDU
- Servlet--Session创建时间
- 组织工程