AcWing 844. 走迷宫
2021-05-18 17:28
阅读:608
标签:href 没有 i++ div com 地图 air 取出 ++
深搜模板题
https://www.acwing.com/problem/content/846/
#includeusing namespace std; const int N=110; int n,m; int g[N][N]; //地图 int d[N][N]; //到起点的距离 typedef pairint,int>PII; PII q[N*N]; //pair int bfs() { int hh=0,tt=0; //hh 队头 ,tt 队尾 q[0]= {0,0}; memset(d,-1,sizeof d); //初始化 d[0][0]=0; //起点到起点的距离为0 int dx[4]= {-1,0,1,0}, dy[4] = {0,1,0,-1}; while(hhtt) { auto t = q[hh++]; //取出队头 for(int i=0; i4; i++) { int x=t.first+dx[i],y=t.second+dy[i]; if(x>=0&&x =0&&y 0&&d[x][y]==-1) { //为空地不是障碍物,而且没有走过, d[x][y]=d[t.first][t.second]+1; //标记距离 q[++tt]= {x,y}; //在放进去 } } } return d[n-1][m-1]; } int main() { cin>>n>>m; for(int i=0; i ) for(int j=0; j ) cin>>g[i][j]; coutendl; return 0; }
AcWing 844. 走迷宫
标签:href 没有 i++ div com 地图 air 取出 ++
原文地址:https://www.cnblogs.com/QingyuYYYYY/p/11739215.html
上一篇:AcWing 842. 排列数字
下一篇:Vuex----核心概念和API
评论
亲,登录后才可以留言!