weixin_52064446 2021-05-29 14:40 采纳率: 100%
浏览 30
已采纳

下面这个迷宫怎么做可以走回头路并且能简化路径,拜托大佬救命呜呜呜

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#include<malloc.h>

int ROWS,COLS;

typedef struct{ int x; int y;}Position;

typedef struct{// int judge[999][999];

int map[999][999];}Maze;

//修建迷宫矩阵(字符串转数组,防止将多位数识别成一位数)

void Init_Maze(Maze *m){

int i=0;

unsigned j;

char str[999];

do{

gets(str);

if(strlen(str)==0) break; for(j=0;j<strlen(str);j++)

{ m->map[i][j]=str[j]-'0'; }

i++;

ROWS=i;

COLS=j;

}while(1);

}

void Pass(Maze *m,Position enter,Position exit)

{

Position current;

current.x=enter.x;

current.y=enter.y;

//寻找路径

do

{

if(0==m>map[current.x[current.y+1]&&COLS>current.y+1)

{

printf("R");

current.y++;

  }else

if(0==m->map[current.x+1][current.y]&&ROWS>current.x+1)

{

printf("D");

current.x++;

}else

if(0==m->map[current.x][current.y-1]&&0<current.y-1)

{

printf("L");

current.y--;

}else

if(0==m->map[current.x-1][current.y]&&0<current.x-1)

{

printf("U");

current.x--;

}

if(current.x==exit.x&&current.y==exit.y) break;

}while(1);

}

int main(int argc,char*argv[])

{

Maze *m=(Maze*)malloc(sizeof(Maze));

Position enter={0,0},exit={ROWS-1,COLS-1};

Init_Maze(m);

exit.x=ROWS-1;

exit.y=COLS-1;

Pass(m,enter,exit);

return 0;

}

  • 写回答

2条回答 默认 最新

  • 有问必答小助手 2021-05-31 15:55
    关注

    您的问题已经有小伙伴解答了,请点击【采纳】按钮,采纳帮您提供解决思路的答案,给回答的人一些鼓励哦~~

    ps:开通问答VIP,享受5次/月 有问必答服务,了解详情↓↓↓

    【电脑端】戳>>>  https://vip.csdn.net/askvip?utm_source=1146287632
    【APP 】  戳>>>  https://mall.csdn.net/item/52471?utm_source=1146287632

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料