解题思路:模拟题目描述的蚂蚁行动规则
注意事项:
参考代码:
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 人评分
简单的a+b (C语言代码)浏览:491 |
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:584 |
C语言程序设计教程(第三版)课后习题10.1 (Java代码)浏览:1443 |
A+B for Input-Output Practice (II) (C语言代码)浏览:998 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:1097 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)浏览:660 |
【计算球体积】 (C语言代码)浏览:1101 |
【计算直线的交点数】 (C语言代码)浏览:1449 |
矩阵加法 (C语言代码)浏览:1722 |
整除问题 (C语言代码)浏览:526 |