poj3984广搜c语言
来源:互联网 发布:linux 升级内核好处 编辑:程序博客网 时间:2024/06/11 08:07
#include <stdio.h>//输入5*5迷宫,输出路径#define MAX_ROW 5 #define MAX_COL 5 struct point { int row, col, predecessor; } queue[512],p; struct node{int x,y;}arr[50];int head = 0, tail = 0; void enqueue(struct point p) { queue[tail++] = p; } struct point dequeue(void) { return queue[head++]; } int is_empty(void) { return head == tail; } int maze[MAX_ROW][MAX_COL];void visit(int row, int col) { struct point visit_point = { row, col, head-1 }; maze[row][col] = 2; enqueue(visit_point); } int main(void) { int i,j;for(i=0;i<5;i++)for(j=0;j<5;j++)scanf("%d",&maze[i][j]);struct point p={0,0,-1}; maze[p.row][p.col] = 2; enqueue(p); while (!is_empty()) { p = dequeue(); if (p.row == MAX_ROW - 1 && p.col == MAX_COL - 1) break; if (p.col+1 < MAX_COL && maze[p.row][p.col+1] == 0) visit(p.row, p.col+1); if (p.row+1 < MAX_ROW && maze[p.row+1][p.col] == 0) visit(p.row+1, p.col); if (p.col-1 >= 0 && maze[p.row][p.col-1] == 0) visit(p.row, p.col-1); if (p.row-1 >= 0 && maze[p.row-1][p.col] == 0) visit(p.row-1, p.col); }i=1;arr[0].x=p.row, arr[0].y=p.col; while (p.predecessor != -1) { p = queue[p.predecessor]; arr[i].x=p.row, arr[i].y=p.col; i++; }j=i;for(i=j-1;i>=0;i--)printf("(%d,%d)\n",arr[i].x,arr[i].y); return 0; }
0 0
- poj3984广搜c语言
- poj3984 迷宫问题(广搜C+深搜C++)
- poj3984-迷宫问题(广搜)
- 【搜索-广搜】poj3984 迷宫问题
- poj1979广搜c语言
- poj3984迷宫问题 广搜+最短路径+模拟队列
- poj3984迷宫问题 广搜+最短路径
- ACM 迷宫问题 poj3984(c语言)
- POJ3984 迷宫问题(深搜DFS+广搜BFS)搜索记录坐标,坑
- C语言 跳马 队列,广搜,结构体
- C语言 六数码 队列,广搜,map函数
- C语言 木乃伊迷宫 队列,广搜,map函数
- poj3984
- poj3984
- POJ3984
- poj3984
- poj3984
- poj3984
- Linux 下 eclipse 创建快捷方式
- jQuery AJAX
- cordova配置文件config.xm
- Xcode7 采用空白模版运行错误
- 文件对象-读操作
- poj3984广搜c语言
- HDU 3530 RMQ+twopointer/单调队列
- 逆序对问题
- HDU - 2121 Ice_cream’s world II(朱刘算法+虚根)
- C语言中的dirent.h说明
- [unix]sysconf、pathconf和fpathconf
- 计算机基本常识
- 开发java程序的基本步骤:JDK中的其他几个工具
- HDU 5391-Zball in Tina Town(威尔逊定理)