poj 3984 迷宫问题

上传人:子 文档编号:42994455 上传时间:2018-06-04 格式:DOC 页数:9 大小:15.47KB
返回 下载 相关 举报
poj 3984 迷宫问题_第1页
第1页 / 共9页
poj 3984 迷宫问题_第2页
第2页 / 共9页
poj 3984 迷宫问题_第3页
第3页 / 共9页
poj 3984 迷宫问题_第4页
第4页 / 共9页
poj 3984 迷宫问题_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《poj 3984 迷宫问题》由会员分享,可在线阅读,更多相关《poj 3984 迷宫问题(9页珍藏版)》请在金锄头文库上搜索。

1、POJPOJ 39843984 迷宫问题迷宫问题/ 定义一个二维数组: / / int maze55 = / 0, 1, 0, 0, 0,/ 0, 1, 0, 1, 0,/ 0, 0, 0, 0, 0,/ 0, 1, 1, 1, 0,/ 0, 0, 0, 1, 0,/ ;/ / 它表示一个迷宫,其中的 1 表示墙壁,0 表示可以走的路,只能横着走或竖着走,不能斜着走,要求编程序找出从左上角到右下角的最短路线。#include using namespace std;class Maze /迷宫类public:void SetMaze(int 5,int,int);/申明是必须指定二维数组的长度

2、 yvoid SetMaze_pot(int,int,int,int);/输入迷宫,以及入口位置,出口位置void GetMaze_way();private:int maze55;int way1002;/路径数组int num;int num1;int num2;/计数器int total_choise100;/总共的可供选择数int ori554;int start_x;int start_y;int finish_x;int finish_y;int Maze_pro(int/输入当前节点坐标以及前一节点坐标,输出下一节点坐标和当前坐标;int main()/ int maze55 =

3、/ 0, 1, 0, 0, 0,/ 0, 1, 0, 1, 0,/ 0, 0, 0, 0, 0,/ 0, 1, 1, 1, 0,/ 0, 0, 0, 1, 0,/ ;int maze55 =1, 0, 1, 1, 1,1, 0, 0, 0, 1,1, 0, 1, 0, 1,1, 0, 0, 0, 0,1, 1, 1, 1, 1,;/你需要测试的迷宫Maze M;M.SetMaze(maze,5,5);/* M.SetMaze_pot(0,0,4,4);*/M.SetMaze_pot(0,1,3,4);/测试迷宫所用的出入口(x,y)M.GetMaze_way();return 0;void M

4、aze:SetMaze(int arr5,int m,int n)/将二维数组传入函数中for (int i=0;i=0if (x = finish_x cout“= 0 ; i-)if (total_choisei 1)num = i;num2 = num;x = waynum - 10;y = waynum - 11;fx = waynum - 20;fy = waynum - 21;tempx = x;tempy = y;total_choisenum-;break;for (i = num;i = 0 ; i-)if (total_choisei 1)num = i;x = waynu

5、m - 10;y = waynum - 11;fx = waynum - 20;fy = waynum - 21;tempx = x;tempy = y;total_choisenum-;break;if (i = -1)/遍历选择数组,假如没有再产生分支路线的可能,则返回 0,是程序结束return 0; if (mazetempx+1tempy!=1waynum0 = tempx-1;waynum1 = tempy;oritempxtempy1 = 0;num+;else if (mazetempxtempy+1 != 1 waynum0 = tempx;waynum1 = tempy-1;oritempxtempy3 = 0;num+;fx = tempx;fy = tempy;return 1;void Maze:GetMaze_way()int x1 = start_x;int x2 = start_x;int y1 = start_y;int y2 = start_y;while (1)if (Maze_pro(x1,y1,x2,y2) = 0)break;

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号