java迷宫问题 华为_牛客网(华为机试--迷宫问题)(借鉴他人)

#include #include #include

int maze[10][10];

int flag = 0;

int DRV_SearchMaze(int max_line, int max_col, int line, int col)

{

if (flag)

{

return 0;

}

if (line == (max_line - 1) && col == (max_col - 1)) //是否到达迷宫边界

{

printf("(%d,%d)\n", line, col);

flag = 1;

return 0;

}

if ((col + 1 < max_col) && (maze[line][col + 1] == 0))//判断行上是否满足

{

printf("(%d,%d)\n", line, col);

DRV_SearchMaze(max_line, max_col, line, col + 1); //递归

}

if ((line + 1 < max_line) && (maze[line + 1][col] == 0))//判断列上是否满足

{

if (flag == 0)

{

printf("(%d,%d)\n", line, col);

DRV_SearchMaze(max_line, max_col, line + 1, col);//递归

}

}

return 0;

}

int main()

{

int line, col;

int i, j;

while (~scanf("%d %d", &line, &col))

{

flag = 0;

for (i = 0; i < line; i++)

{

for (j = 0; j < col; j++)

scanf("%d", &maze[i][j]);

}

DRV_SearchMaze(line, col, 0, 0);

}

return 0;

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值