当前位置:首页 » 操作系统 » 迷宫算法

迷宫算法

发布时间: 2022-01-09 01:51:13

A. 李氏迷宫算法的发展

迷宫算法最初是由C.Y.Lee提出的,又称为李氏算法或波扩法,其优点是只要最短路径存在,就一定能找到,然而其缺点也是明显的,对于n×n的网格空间,它需要O(n2)的运行时间和存储空间并产生了较多的层间引线孔。

C.Y.LEE简介:

William C.Y.Lee(威廉.C.Y.李)博士,国际着名科学家,教育家,近代移动通信奠基人之一。
李博士于1963年获得美国Ohio State University电气工程博士学位;1964~1979年,开创了美国贝尔试验室下的移动无线电通信研究室;1979~1985年,任美国ITT公司国防通信部的尖端技术开发部主管;1985~2000年,任美国Vodafone AirTouch公司副总裁和首席科学家。2000~2005年,任美国LinkAir通信公司董事长,现任美国Treyspan公司董事长。
李博士因开发了商用的AMPS和CDMA技术而享誉全世界,在其几十年的科研生涯中,获得殊荣无数。1982年成为IEEE会员,1987年成为全美无线电俱乐部会员,1982~1998年应美国George Washington University邀请,主讲最早的面向产业的蜂窝和移动通信课程。还有ITTDCD的技术贡献奖(1984),Ohio State University有突出贡献的校友(1990),IEEE VTSAvant Garde奖(1990),美国CTIA的奖励证书(1994),IEEE车载技术协会技术服务奖(1996),中美(SATEC)杰出贡献证书(1997)以及贝尔试验室致力服务奖(1998),等等。李博士还是美国国家竞争委员会的会员,美国加利福尼亚州科学技术委员会成员,北京航空航天大学、西南交大的名誉教授。
李博士为蜂窝通信领域作出了巨大的贡献。他的重要专着和教科书《无线与蜂窝通信》(1989年第1版,1997年第2版,本书是2006年第3版的中文版)风靡全球,已被翻译成俄文版、汉语版、日语版、韩语版等多种文字。在该书第1版的序言里,李博士就明确阐述了他为蜂窝通信产业制定的目标:“让我们携起手来,使蜂窝产业发挥它最大的潜力,我们的目标是:在不远的将来,让便携式蜂窝电话把我们的通话遍及世界每一个角落。”

B. 迷宫算法问题

栈走到底也可以回过头来继续探索啊,要不怎么叫深度【遍历】。

C. 求解迷宫的递归算法

#include<stdio.h>
#include<malloc.h>
#define M 10
#define N 10
struct node
{
int flag;
int x,y;
};
struct link
{
struct node lnode;
struct link *next;
struct link *pri;
};
struct link *head;
struct node maze[M][N];
int maze_flag[M][N]={{1,1,1,1,1,1,1,1,1,1},
{1,1,0,1,0,0,0,1,0,1},
{1,0,0,1,0,0,0,1,0,1},
{1,0,0,0,0,1,1,0,0,1},
{1,0,1,1,1,0,0,0,0,1},
{1,0,0,0,1,0,0,0,0,1},
{1,0,1,0,0,0,1,0,0,1},
{1,0,1,1,1,0,1,1,0,1},
{1,1,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1}};
int judge(int i,int j);
void in_link(struct node nmaze);
void out_link();
void out_put();
void main()
{
int i,j;
head=(struct link *)malloc(sizeof(struct link));
head->next=head;
head->pri=head;
for(i=0;i<M;i++)
{
for(j=0;j<N;j++)
{
maze[i][j].x=i;
maze[i][j].y=j;
maze[i][j].flag=maze_flag[i][j];
}
}
printf("the maze is:\n");
for(i=0;i<M;i++)
{
for(j=0;j<N;j++)
{
printf("%2d",maze_flag[i][j]);
}
printf("\n");
}
head->next=(struct link *)malloc(sizeof(struct link));
head->pri=head->next;
head->next->pri=head;
head->next->next=head;
head->next->lnode.x=1;
head->next->lnode.y=1;
head->next->lnode.flag=1;
printf("wether to find the way?\n");
if(judge(1,1)==1)
printf("the end!\n");
}
int judge(int i,int j)
{
struct node (*pmaze)[N]=maze;
if(pmaze[i][j+1].flag==0)
{
j++;
if((pmaze[i][j].x==M-2)&&(pmaze[i][j].y==N-2))
{
printf("success to find the way!\n");
out_put();
return(1);
}
pmaze[i][j].flag=1;
in_link(pmaze[i][j]);
printf("goin to judge\n");
return(judge(i,j));

}
else
{
if(pmaze[i+1][j].flag==0)
{
i++;
if((pmaze[i][j].x==M-2)&&(pmaze[i][j].y==N-2))
{
printf("success to find the way!\n");
out_put();
return(1);
}
pmaze[i][j].flag=1;
in_link(pmaze[i][j]);
return(judge(i,j));
}
else
{
if(pmaze[i][j-1].flag==0)
{
j--;
if((pmaze[i][j].x==M-2)&&(pmaze[i][j].y==N-2))
{
printf("success to find the way!\n");
out_put();
return(1);
}
pmaze[i][j].flag=1;
in_link(pmaze[i][j]);
return(judge(i,j));
}
else
{
if(pmaze[i-1][j].flag==0)
{
i--;
if((pmaze[i][j].x==M-2)&&(pmaze[i][j].y==N-2))
{
printf("success to find the way!\n");
out_put();
return(1);
}
pmaze[i][j].flag=1;
in_link(pmaze[i][j]);
return(judge(i,j));
}
else
{
out_link();
struct link *q;
q=head;
while(q->next!=head)
{
q=q->next;
}
judge(q->lnode.x,q->lnode.y);
}
}
}
}
}
void in_link(struct node nmaze)
{
struct link *p;
p=head;
while(p->next!=head)
{
p=p->next;
}
p->next=(struct link *)malloc(sizeof(struct link));
p->next->pri=p;
head->pri=p->next;
p->next->next=head;
p=p->next;
p->lnode.x=nmaze.x;
p->lnode.y=nmaze.y;
p->lnode.flag=nmaze.flag;
}
void out_link()
{
struct link *p;
p=head;
while(p->next!=head)
{
p=p->next;
}
p->pri->next=p->next;
head->pri=p->pri;
free(p);
}
void out_put()
{
struct link *r;
r=head;
while(r->next!=NULL)
{
r=r->next;
printf("%2d%2d\n",r->lnode.x,r->lnode.y);
}
printf("%d%d\n",r->lnode.x,r->lnode.y);
}

D. 求走迷宫的算法!(计算机的算法)(编程也可以

我的思路:
按照人类走迷宫的方法,贴着左边走,左边有路就向左走,左边没路向前走,左边前面都没路向右走

机器人的应该是:1.判断左边是否有墙,无墙:机器人左转,前进一步,继续判断左。。
2.左边有墙,则判断前方是否有墙,无则向前一步,跳回第一步
3.前方有墙(此时状态是左有墙,前有墙),则向机器人右转,跳回第一步
另外有个前提条件,机器人转弯需要原地转,有转弯半径的肯定不行。
还有个问题,就是机器人自己不知道自己已经从迷宫出来了,会一直走。。

E. 求迷宫算法,c++语言

/*地图路径求解程序,用VC++编写的,在TC下运行可能有问题的。
问题的情况可能是:不认识false和true,去掉下面定义的两行前面的“/*”即可定义他们
也可能有变量名称过长的错误,如果是那样,就麻烦你自己修改变量名吧,把所有的变量名称替换为少于8字节的*/
#include<stdio.h>
#include<stdlib.h>
#define ROW 9/*定义行数*/
#define COL 13/*定义列数*/
///*#define false 0/*定义false为0,如果在c语言中需要这个,就把前面的“/*”去掉*/
///*#define true 1/*定义true为1,如果在C语言中需要这个,就把前面的“/*”去掉*/

typedef struct RowAndColPath{
int r;
int c;
}RowAndColPath;/*定义结构体实现走步过程的记录*/

int Move[4][2]={{0,1},{1,0},{-1,0},{0,-1}};/*4个方向*/
RowAndColPath path[ROW*COL];/*走动过程的记录*/
bool ResultFlag=false;/*找到解的标志*/

bool GettingPath(int step,int CurrentRow,int CurrentCol,int ResultRow,int ResultCol,int MapWay[][COL]);/*递归求解方法*/

void main()
{
int MapWay[ROW][COL]={
{1,1,1,1,1,1,1,1,0,1,1,1,1},
{0,0,0,1,1,0,0,0,0,1,1,1,1},
{1,1,0,1,1,1,1,1,0,0,1,1,1},
{1,1,0,0,0,0,1,1,1,0,1,1,1},
{1,1,0,1,1,0,0,0,0,0,0,0,1},
{1,1,0,0,1,1,1,1,1,1,1,0,1},
{1,1,1,0,0,0,0,0,0,1,1,0,1},
{1,1,1,0,1,1,1,1,0,0,0,0,1},
{1,1,1,0,0,0,1,1,1,1,1,1,1}};/*定义地图*/

int CurrentRow=1,CurrentCol=0,ResultRow=0,ResultCol=8;/*定义初始和结束位置*/
path[0].r=CurrentRow;
path[0].c=CurrentCol;/*初始位置进入历史的第一步*/
if(GettingPath(1,CurrentRow,CurrentCol,ResultRow,ResultCol,MapWay))/*如果走动成功*/
printf("恭喜!查找成功!\n");
else
printf("抱歉,查找失败!\n");
}

bool GettingPath(int step,int CurrentRow,int CurrentCol,int ResultRow,int ResultCol,int MapWay[][COL])
{
int i,j;

for(i=0;i<4;i++)/*依次对4个方向搜索*/
{
if(ResultFlag)
return true;
CurrentRow+=Move[i][0];
CurrentCol+=Move[i][1];/*先按该方向前进一步*/
if((CurrentRow>=0)&&(CurrentRow<ROW)&&(CurrentCol>=0)&&(CurrentRow<COL))/*如果还在地图内部*/
{
if(MapWay[CurrentRow][CurrentCol]==0)/*下一步可以走*/
{
for(j=0;j<step;j++)/*判断是不是重复了以前走过的路*/
{
if((path[j].r==CurrentRow)&&(path[j].c==CurrentCol))
break;
}
if(j==step)/*如果没有走过这个点,就走*/
{
path[step].r=CurrentRow;
path[step].c=CurrentCol;/*计入该步*/
step++;
if((CurrentRow==ResultRow)&&(CurrentCol==ResultCol))/*如果已到达目的地*/
{
ResultFlag=true;
printf("路径如下:\n\n");
for(j=0;j<step;j++)
printf("第 %d 步:\t%d\t%d\n",j,path[j].r,path[j].c);
return true;
}
else
{
if(step>=ROW*COL)/*如果已经走遍了地图,就宣布失败*/
return 0;
if(!ResultFlag)
GettingPath(step,CurrentRow,CurrentCol,ResultRow,ResultCol,MapWay);/*没有到达目的,继续走*/
}
}
else/*如果已经走过这一点,退回去*/
{
CurrentRow-=Move[i][0];
CurrentCol-=Move[i][1];;
}
}
else/*如果该点不可走,退回去*/
{
CurrentRow-=Move[i][0];
CurrentCol-=Move[i][1];;
}
}
else/*如果该步出地图了,退回去*/
{
CurrentRow-=Move[i][0];
CurrentCol-=Move[i][1];;
}
}
if(ResultFlag)
return true;
return false;/*无路可走*/
}

F. 数据结构算法(c语言) 迷宫求解

注释非常详细,希望对你有所帮助。
#include<stdio.h>
#include<stdlib.h>
#define M 15
#define N 15
struct mark //定义迷宫内点的坐标类型
{
int x;
int y;
};

struct Element //"恋"栈元素,嘿嘿。。
{
int x,y; //x行,y列
int d; //d下一步的方向
};

typedef struct LStack //链栈
{
Element elem;
struct LStack *next;
}*PLStack;

/*************栈函数****************/

int InitStack(PLStack &S)//构造空栈
{
S=NULL;
return 1;
}

int StackEmpty(PLStack S)//判断栈是否为空
{
if(S==NULL)
return 1;
else
return 0;
}

int Push(PLStack &S, Element e)//压入新数据元素
{
PLStack p;
p=(PLStack)malloc(sizeof(LStack));
p->elem=e;
p->next=S;
S=p;
return 1;
}

int Pop(PLStack &S,Element &e) //栈顶元素出栈
{
PLStack p;
if(!StackEmpty(S))
{
e=S->elem;
p=S;
S=S->next;
free(p);
return 1;
}
else
return 0;
}

/***************求迷宫路径函数***********************/
void MazePath(struct mark start,struct mark end,int maze[M][N],int diradd[4][2])
{
int i,j,d;int a,b;
Element elem,e;
PLStack S1, S2;
InitStack(S1);
InitStack(S2);
maze[start.x][start.y]=2; //入口点作上标记
elem.x=start.x;
elem.y=start.y;
elem.d=-1; //开始为-1
Push(S1,elem);
while(!StackEmpty(S1)) //栈不为空 有路径可走
{
Pop(S1,elem);
i=elem.x;
j=elem.y;
d=elem.d+1; //下一个方向
while(d<4) //试探东南西北各个方向
{
a=i+diradd[d][0];
b=j+diradd[d][1];
if(a==end.x && b==end.y && maze[a][b]==0) //如果到了出口
{
elem.x=i;
elem.y=j;
elem.d=d;
Push(S1,elem);
elem.x=a;
elem.y=b;
elem.d=886; //方向输出为-1 判断是否到了出口
Push(S1,elem);
printf("\n0=东 1=南 2=西 3=北 886为则走出迷宫\n\n通路为:(行坐标,列坐标,方向)\n");
while(S1) //逆置序列 并输出迷宫路径序列
{
Pop(S1,e);
Push(S2,e);
}
while(S2)
{
Pop(S2,e);
printf("-->(%d,%d,%d)",e.x,e.y,e.d);
}
return; //跳出两层循环,本来用break,但发现出错,exit又会结束程序,选用return还是不错滴
}
if(maze[a][b]==0) //找到可以前进的非出口的点
{
maze[a][b]=2; //标记走过此点
elem.x=i;
elem.y=j;
elem.d=d;
Push(S1,elem); //当前位置入栈
i=a; //下一点转化为当前点
j=b;
d=-1;
}
d++;
}
}
printf("没有找到可以走出此迷宫的路径\n");
}

/*************建立迷宫*******************/
void initmaze(int maze[M][N])
{
int i,j;
int m,n; //迷宫行,列 [/M]

printf("请输入迷宫的行数 m=");
scanf("%d",&m);
printf("请输入迷宫的列数 n=");
scanf("%d",&n);
printf("\n请输入迷宫的各行各列:\n用空格隔开,0代表路,1代表墙\n",m,n);
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
scanf("%d",&maze[i][j]);
printf("你建立的迷宫为(最外圈为墙)...\n");
for(i=0;i<=m+1;i++) //加一圈围墙
{
maze[i][0]=1;
maze[i][n+1]=1;
}
for(j=0;j<=n+1;j++)
{
maze[0][j]=1;
maze[m+1][j]=1;
}
for(i=0;i<=m+1;i++) //输出迷宫
{
for(j=0;j<=n+1;j++)
printf("%d ",maze[i][j]);
printf("\n");
}
}

void main()
{
int sto[M][N];
struct mark start,end; //start,end入口和出口的坐标
int add[4][2]={{0,1},{1,0},{0,-1},{-1,0}};//行增量和列增量 方向依次为东西南北 [/M]

initmaze(sto);//建立迷宫

printf("输入入口的横坐标,纵坐标[逗号隔开]\n");
scanf("%d,%d",&start.x,&start.y);
printf("输入出口的横坐标,纵坐标[逗号隔开]\n");
scanf("%d,%d",&end.x,&end.y);

MazePath(start,end,sto,add); //find path
system("PAUSE");
}
测试数据,算法复杂度你就自己来写吧,如果你连这都不自己做,那你一定是在应付作业。劝你还是自己运行测试一下吧,免得答辩时老师问你,什么都不知道,那你就悲剧了。祝你好运!!

G. 迷宫算法复杂度如何计算

迷宫生成可以O(n*m)完成。走迷宫的话可以O(n*m*2)左右。
只要记录走到每一格的最优解就可以了。
最好不要用深度优先搜索。用广度优先的实现方便。

H. 递归算法解决迷宫问题

给你给伪算法:(设坐标为x,y,坐标向右和下延生。) 函数: { 判断当前是不是(7,7),如果是,表示走出迷宫。打印轨迹 1 尝试往左先走一步(x-1,如果x小于0,或者对应位置标识为阻塞) 2 1如果成功,用本函数递归调用左走一步的坐标,并记下当前位置到轨迹列表。 3 尝试往前先走一步(y+1,如果y小于0,或者对应位置标识为阻塞) 4 3如果成功,用本函数递归调用前走一步的坐标,并记下当前位置到轨迹列表。 5 尝试往右先走一步(x+1,如果x小于0,或者对应位置标识为阻塞) 6 5如果成功,用本函数递归调用前走一步的坐标,并记下当前位置到轨迹列表。 如果是(0,0),表示没有合适的路径可走出迷宫。 如果不是(0,0),将轨迹列表最后一位弹出。 }

I. 迷宫问题算法设计!!急急急(c语言)

额,又是课程设计。。。
迷宫类算法,用栈,队列来做。不过一般来队列,因为队列能够在较短时间内求出最短路径。
在网上搜下,很多的。。
你的要求很难达到。。。

热点内容
实测华为编译器 发布:2024-09-19 23:50:52 浏览:821
linux汇总 发布:2024-09-19 23:46:39 浏览:452
阿里云服务器环境搭建教程 发布:2024-09-19 23:21:58 浏览:837
黄色文件夹图标 发布:2024-09-19 23:19:22 浏览:684
mysql数据库导出导入 发布:2024-09-19 23:00:47 浏览:183
lua脚本精灵 发布:2024-09-19 23:00:41 浏览:659
任务栏文件夹图标 发布:2024-09-19 22:54:25 浏览:101
解压来一波 发布:2024-09-19 22:46:36 浏览:933
mysqlpythonubuntu 发布:2024-09-19 22:46:27 浏览:501
服务器请求获取ip地址 发布:2024-09-19 22:33:25 浏览:515