POJ_3984经典迷宫问题
来源:互联网 发布:手机版导航源码 编辑:程序博客网 时间:2024/04/30 01:26
//记录路径//
AC代码:
#include<stdio.h>#include<string.h>#define max 10int map[max][max];int vis[max][max];int dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}};struct node{ int x,y;}queue[max*max];int a[max*max];int b[max*max];int cnt;int p[max*max];void print(int k){ int i; int t=p[k]; if(t==0) { printf("(0, 0)\n"); printf("(%d, %d)\n",a[k],b[k]); } else { print(t); printf("(%d, %d)\n",a[k],b[k]); }}void bfs(int x,int y){ struct node now,pre; queue[0].x=0; queue[0].y=0; int e=0,h=1; p[0]=-1; while(e<h) { pre=queue[e]; if(pre.x==4&&pre.y==4) { print(e); return; } int i; for(i=0;i<4;i++) { now.x=pre.x+dir[i][0]; now.y=pre.y+dir[i][1]; if(now.x>=0&&now.x<5&&now.y>=0&&now.y<5&&!vis[now.x][now.y]&&map[now.x][now.y]==0) { vis[now.x][now.y]=1; queue[h]=now; a[h]=now.x; b[h]=now.y; p[h]=e; h++; } } e++; } return;}int main(){ int i,j; cnt=0; for(i=0;i<5;i++) { for(j=0;j<5;j++) { scanf("%d",&map[i][j]); } } memset(vis,0,sizeof(vis)); bfs(0,0); return 0;}
0 0
- POJ_3984经典迷宫问题
- poj_3984 迷宫问题
- poj_3984迷宫问题
- K_迷宫问题(POJ_3984)
- POJ_3984 迷宫问题(广搜)
- Poj_3984走迷宫(广搜)
- 经典迷宫问题BFS
- 经典迷宫问题DFS
- 经典迷宫问题
- 经典迷宫问题
- 经典迷宫问题
- 经典迷宫问题1
- 经典迷宫问题BFS
- 经典迷宫问题—BFS
- 经典算法之迷宫问题
- 经典迷宫最短路问题
- 经典问题-老鼠走迷宫问题求解
- 迷宫问题 经典bfs问题【bfs】
- java统计图echarts
- log4j使用介绍
- HDU 1026 Ignatius and the Princess I
- 创业/商业计划书10大禁忌
- cocos2d-x3.2——启动过程[Win32]
- POJ_3984经典迷宫问题
- hibernate session 執行原生態SQL
- Linux下路径不能有空格
- 找回丢失的权限
- mini2440-设置和读取时间
- HDOJ 2089 不要62
- 创建基本表、数据库、列级/表级约束
- C++面向对象编程(二)之 深拷贝和浅拷贝
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)