ACM 迷宫问题 poj3984(c语言)
来源:互联网 发布:2017免费下载农村淘宝 编辑:程序博客网 时间:2024/05/22 16:06
#include<stdio.h>#include<stdlib.h>#define num 5 int dx[4]={1,0,-1,0};int dy[4]={0,-1,0,1}; //dx dy用来方便访问该点4个方向上邻接点 int data[5][5]; //迷宫数据 struct node { int x,y,pre; }queue[100]; //队列 int visit[num][num]={0}; void output(int point); int gonext(int a,int b); void input() ; void bfs(int a,int b); int gonext(int a,int b) //判断该点是否可访问 {if(0<=a&&a<=4&&0<=b&&b<=4&&data[a][b]==0 ) return 1;elsereturn 0;} void input() //初始化迷宫 {int i,j;for(i=0;i<5;i++)for(j=0;j<5;j++)scanf("%d",&data[i][j]); } void bfs(int a,int b){ int front,rear; int i; int j=0; int next_x,next_y;//邻接点坐标 front=0; rear=1; queue[front].x=a; queue[front].y=b; queue[front].pre=-1; while(front<rear) { for(i=0;i<4;i++) { next_x=queue[front].x+dx[i]; next_y=queue[front].y+dy[i]; if(gonext(next_x,next_y)==1&&visit[next_x][next_y]==0) { visit[next_x][next_y]=1;//已访问 queue[rear].x=next_x; queue[rear].y=next_y; queue[rear].pre=front; rear++; } if( next_x == 4 &&next_y == 4) { printf("(0, 0)\n"); output(rear-1); return 0 ; } } front++; }} void output(int point) { if(queue[point].pre!=-1) { output( queue[point].pre);printf("(%d, %d)\n", queue[point].x, queue[point].y); } } int main(void) { input(); bfs(0,0); return 0; }
0 0
- ACM 迷宫问题 poj3984(c语言)
- ACM篇:POJ3984--迷宫问题
- POJ3984 迷宫问题 BFS
- POJ3984 迷宫问题
- HUD--POJ3984 迷宫问题
- POJ3984 迷宫问题 BFS
- poj3984 迷宫问题
- poj3984(迷宫问题)
- poj3984 迷宫问题
- [POJ3984]迷宫问题
- poj3984 迷宫问题(BFS)
- POJ3984 迷宫问题
- POJ3984 迷宫问题【BFS】
- poj3984 迷宫问题
- Poj3984- dfs -迷宫问题
- poj3984迷宫问题(bfs)
- poj3984迷宫问题
- poj3984 迷宫问题
- C预言的输入输出函数
- 子线程中循环操作UI线程时导致子线程无法正常结束的问题总结
- 街道问题 (DP)
- Combination Sum II
- 【软考】(一)编译原理-文法
- ACM 迷宫问题 poj3984(c语言)
- WPF多线程
- iOS开发(10)UISegmentedControl
- NY86 找球号(一)
- C++ 析构函数 为何一般定义为虚函数
- MySQL游标循环
- Android fill_parent、wrap_content和match_parent的区别
- GUI(十)
- 将截断字符串或二进制数据。语句已终止……”问题的解决