month


私信TA

用户名:lanqiaobeiTest

访问量:2185

签 名:

等  级
排  名 10563
经  验 1027
参赛次数 1
文章发表 7
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

TA的其他文章

连号区间数
浏览:158
倍数问题Python解法
浏览:429
修改数组题解
浏览:339

解题思路:

注意事项:

参考代码:

def white(mapList, x, y, direction, steps):
    mapList[x][y] = 1
    if direction == "U":
        y -= 1
        direction = "L"
    elif direction == "D":
        y += 1
        direction = "R"
    elif direction == "L":
        x += 1
        direction = "D"
    else:
        x -= 1
        direction = "U"
    steps -= 1
    return mapList, x, y, direction, steps

def black(mapList, x, y, direction, steps):
    mapList[x][y] = 0
    if direction == "U":
        y += 1
        direction = "R"
    elif direction == "D":
        y -= 1
        direction = "L"
    elif direction == "L":
        x -= 1
        direction = "U"
    else:
        x += 1
        direction = "D"
    steps -= 1
    return mapList, x, y, direction, steps


m, n = map(int, input().strip().split())
mapList = [[int(temp) for temp in input().strip().split()] for i in range(m)]
inputList = input().strip().split()
x, y = int(inputList[0]), int(inputList[1])
direction = inputList[2]
steps = int(inputList[-1])

while steps!=0:
    if mapList[x][y]==1:
        mapList, x, y, direction, steps = black(mapList, x, y, direction, steps)
    else:
        mapList, x, y, direction, steps = white(mapList, x, y, direction, steps)
print(x, y)


 

0.0分

2 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区