解题思路:
注意事项:
参考代码:
from itertools import cycle m, n = map(int, input().split()) map_ = [list(map(int, input().split()))[:n] for _ in range(m)] res, visited = [map_[0][0]], [[False for _ in range(n)] for _ in range(m)] direction = cycle([[1, 0], [0, 1], [-1, 0], [0, -1]]) x, y, cnt = 0, 0, 0 visited[0][0] = True while 1: temp = next(direction) while 1: if 0 <= x + temp[0] < m and 0 <= y + temp[1] < n and not visited[x + temp[0]][y + temp[1]]: x, y = x + temp[0], y + temp[1] visited[x][y] = True res.append(map_[x][y]) cnt = 0 else: cnt += 1 break if cnt == 4: break print(*res)
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题6.7 (C++代码)(经常这样写会不会被打死)浏览:2504 |
C二级辅导-阶乘数列 (C语言代码)浏览:614 |
【数组的距离】 (C语言代码)浏览:728 |
本人酷爱递归实现很多问题,这里也是浏览:545 |
WU-整数平均值 (C++代码)浏览:1237 |
DNA (C语言描述,数据结构)浏览:850 |
C语言程序设计教程(第三版)课后习题5.8 (C语言代码)浏览:672 |
1025题解浏览:732 |
1048题解(读入回车问题)浏览:554 |
局部变量作函数返回值的问题浏览:963 |