解题思路:
注意事项:
参考代码:
def get(st,mmp,n,m): for i in range(n): for j in range(m): if mmp[i][j] == st: return [i, j, 0] def bfs(mmp): x = [1, -1, 0, 0] y = [0, 0, 1, -1] li = get('@', mmp, a, b) end = get('*', mmp, a, b) queue = [] ans = 0 queue.append(li) while queue: mmp[li[0]][li[1]] = '#' xx, yy, ans = queue.pop(0) if xx == end[0] and yy == end[1]: return ans for i in range(4): lx = xx + x[i] ly = yy + y[i] if lx >= 0 and lx < a and ly >= 0 and ly < b and mmp[lx][ly] != '#': queue.append([lx, ly, ans + 1]) mmp[lx][ly] = '#' return -1 while True: a,b=map(int,input().split()) if a ==0 and b==0: break mmp = [ list(input()) for _ in range(a)] print(bfs(mmp))
0.0分
1 人评分
数列排序 (C语言代码)浏览:835 |
C语言程序设计教程(第三版)课后习题7.4 (C语言代码)浏览:606 |
C二级辅导-阶乘数列 (C语言代码)浏览:691 |
【金明的预算方案】 (C++代码)浏览:843 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:545 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:569 |
Tom数 (C语言代码)浏览:725 |
母牛的故事 (C语言代码)浏览:453 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:511 |
简单的a+b (C语言代码)浏览:560 |