解题思路:

注意事项:

参考代码:

m,n=map(int,input().split())
mat=[]
for i in range(m):
  li=list(map(int,input().split()))
  mat.append(li)
li=input().split()
x=int(li[0])
y=int(li[1])
s=li[2]
k=int(li[3])
# 蚂蚁的移动规则十分简单:
# 若蚂蚁在黑格,右转90度,将该格改为白格,并向前移一格;
# 若蚂蚁在白格,左转90度,将该格改为黑格,并向前移一格。
def left(s):
  if s=='U':
     return 'L'
  elif s=='D':
     return 'R'
  elif s=='L':
     return 'D'
  elif s=='R':
     return 'U'
def right(s):
  if s=='U':
     return 'R'
  elif s=='D':
     return 'L'
  elif s=='L':
     return 'U'
  elif s=='R':
     return 'D'
def forward(s):
  if s=='U':
     return [-1,0]
  elif s=='D':
     return  [1,0]
  elif s=='L':
     return  [0,-1]
  elif s=='R':
     return [0,1]
def move(x,y,s,k):
  if k>0:
     if mat[x][y]==1:
        s=right(s)
     elif   mat[x][y]==0:
        s=left(s)
     mat[x][y]=1-mat[x][y]
     x+=forward(s)[0]
     y+=forward(s)[1]
     move(x, y, s, k-1)
  elif k==0:
     print(x,y)
move(x,y,s,k)

 

0.0分

0 人评分

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

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区