解题思路:模拟题目描述的蚂蚁行动规则
注意事项:
参考代码:
m, n = map(int, input().strip().split()) matrix = [] for i in range(m): matrix.append(list(map(int, input().strip().split()))) temp = input().strip().split() x, y, s, k = int(temp[0]), int(temp[1]), temp[2], int(temp[3]) directions = {"L": [(0, -1), ("D", "U")], "U": [(-1, 0), ("L", "R")], "R": [(0, 1), ("U", "D")], "D": [(1, 0), ("R", "L")]} # 第一个元组对应移动,第二个元组对应(左转,右转) while k: if matrix[x][y] == 0:#白格 matrix[x][y] = 1#改黑格 s = directions[s][1][0] #左转90->向下,即D if 0 <= x + directions[s][0][0] <= m and 0 <= y + directions[s][0][1] <= n:#边界就不移动,只执行前面的改颜色和改方向 x += directions[s][0][0] y += directions[s][0][1] else: matrix[x][y] = 0 s = directions[s][1][1] if 0 <= x + directions[s][0][0] <= m and 0 <= y + directions[s][0][1] <= n: x += directions[s][0][0] y += directions[s][0][1] k -= 1 print(x, y)
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题6.4 (C语言代码)浏览:651 |
九宫重排 (C++代码)浏览:1333 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:1520 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:543 |
C语言程序设计教程(第三版)课后习题6.5 (C语言代码)浏览:758 |
用筛法求之N内的素数。 (C语言代码)浏览:806 |
【明明的随机数】 (C语言代码)浏览:787 |
1051(奇了怪了)浏览:649 |
交换Easy (C语言代码)浏览:761 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:673 |