非递归数组迷宫_迷宫非递归算法

2020-02-28 其他范文 下载本文

非递归数组迷宫由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“迷宫非递归算法”。

用于解决迷宫问题:

#include “stdafx.h”

#define Max 100

#define MMM 1000

int main(intargc, char* argv[])

{int i=0,j=0,x=0,y=0,z=0;

int a[Max][Max];

int labyrinth(int a[Max][Max],intx,int y);

printf(“nIt's a funny game!n”);

printf(“nYou can create a labyrinth And find its route via this programninsructions:n”);printf(“1.'1'stands for ways obstruent n2.'0' stands for ways availablen”);printf(“nThe size of your labyrinth is :n”);

scanf(“%d,%d”,&x,&y);

printf(“nNow Enter your numbers:n”);

for(i=1;i

for(j=1;j

{scanf(“%d ”,&a[i][j]);}

for(j=0;j

{

a[0][j]=1;

a[x+1][j]=1;

}

for(i=0;i

{

a[i][0]=1;

a[i][y+1]=1;

}

a[x+1][y+1]=1;

for(i=0;i

for(j=0;j

{

printf(“%d”,a[i][j]);

if(j==y+1)

printf(“n”);

}

labyrinth(a,x+1,y+1);

return 0;

}

int labyrinth(int a[Max][Max],intm,int n)

{

int STACK[MMM][3];

int move[8][2]={{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1-1}};intp,i,j,g,h,top=0,k=0;

a[1][1]=2;

STACK[0][0]=1;

STACK[0][1]=1;

STACK[0][2]=1;

while(top>=0)

{

i=STACK[top][0];

j=STACK[top][1];

k=STACK[top--][2]+1;

while(k

{

g=i+move[k][0];

h=j+move[k][1];

if(g==m-2&&h==n-2&&a[g][h]==0)

{

printf(“We've got a way!n”);

for(p=0;p

printf(“%2d,%2d”,STACK[p][0],STACK[p][1]);printf(“%2d,%2d”,i,j);

printf(“%3d,%3d”,m-1,n-1);

return 1;

}

if(a[g][h]==0)

{

a[g][h]=2;

STACK[++top][0]=i;

STACK[top][1]=j;

STACK[top][2]=k;

i=g;j=h;k=0;

}

k++;

}} printf(“Your labyrinth has no ways outn”);return 0;

《非递归数组迷宫.docx》
将本文的Word文档下载,方便收藏和打印
推荐度:
非递归数组迷宫
点击下载文档
相关专题 迷宫非递归算法 递归 数组 迷宫 迷宫非递归算法 递归 数组 迷宫
[其他范文]相关推荐
    [其他范文]热门文章
      下载全文