uva1600 Patrol Robot —— bfs
来源:互联网 发布:下载youtube的软件 编辑:程序博客网 时间:2024/05/20 16:42
代码如下:
#include<stdio.h>//uva1600 巡逻机器人 BFS#include<string.h>struct{ int x,y,z,step;}q[1001];//vis为三维,位置+走过了多少障碍int map[100][25], vis[100][25][25];int d[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};int bfs(int m,int n,int k){ int head = 0, tail = 1; vis[1][1][0] = 1; q[0].x = q[0].y = 1; q[0].step = q[0].z = 0; memset(vis,0,sizeof(vis)); for(int i = 1; i<=m; i++) for(int j = 1; j<=n; j++) scanf("%d",&map[i][j]); while(tail!=head) { for(int i = 0; i<4; i++) { int xx = q[head].x + d[i][0]; int yy = q[head].y + d[i][1]; if(xx==m && yy==n) return q[head].step+1; if(xx>0 && xx<=m && yy>0 && yy<=n && !vis[xx][yy][q[head].z+1]) { if(map[xx][yy]) if(q[head].z+1<=k) { vis[xx][yy][q[head].z+1] = 1; q[tail].x = xx; q[tail].y = yy; q[tail].step = q[head].step+1; q[tail].z = q[head].z+1; tail = tail%1000+1; } if(!map[xx][yy]) { vis[xx][yy][0] = 1; q[tail].x = xx; q[tail].y = yy; q[tail].step = q[head].step+1; q[tail].z = 0; tail = tail%1000+1; } } } head = head%1000+1; } return -1;}int main(){ int m,n,k,T; scanf("%d",&T); while(T--) { scanf("%d%d%d",&m,&n,&k); printf("%d\n",bfs(m,n,k)); } return 0;}
0 0
- uva1600 Patrol Robot —— bfs
- Uva1600——Patrol Robot
- uva1600-Patrol Robot(bfs)
- Uva1600 - Patrol Robot(bfs解法)
- 习题6-5 UVa1600 Patrol Robot(BFS)
- uva1600 Patrol Robot 巡逻机器人(BFS)
- Uva1600 Patrol Robot 【bfs】【习题6-5】
- uva1600 - Patrol Robot
- UVA1600 - Patrol Robot
- uva1600 Patrol Robot
- uva1600 -- Patrol Robot
- UVA1600 Patrol Robot
- UVa 1600 Patrol Robot——bfs
- Patrol Robot UVa1600巡逻机器人
- Patrol Robot UVa1600巡逻机器人
- Patrol Robot(BFS)
- 1600 - Patrol Robot(BFS)
- Patrol Robot (BFS典例)
- begin come~on~
- 【问题解决】 org.apache.commons.dbcp.SQLNestedException Cannot create PoolableConnectionFactory
- OpenJudge-Mooc 2:拨钟问题
- 重拾代码
- 前端开发工程师,为什么选择Angular 2?
- uva1600 Patrol Robot —— bfs
- C++抽象编程——函数与库(1)
- 独立集
- 线性表实现之顺序表——MyArrayList
- python编译错误(1)字符编码问题UnicodeDecodeError: 'ascii' codec
- ubuntu+idea+scala第一个scala程序
- web攻击详解
- Http七个方法与requests库七个方法
- EditText作为密码输入框,隐藏输入密码