其他分享
首页 > 其他分享> > LCP 03.机器人大冒险

LCP 03.机器人大冒险

作者:互联网

def robot(command, obstacles, x, y):
xx = 0
yy = 0
tmp = []
for c in command:
if c == 'U':
yy += 1
if c == 'R':
xx += 1
tmp.append([xx, yy])
#print(tmp)
index, times= -1, -1
for i in range(len(tmp)):
tx, ty = tmp[i]
if (x-tx)%xx ==0 and (y-ty)%yy == 0 and (x-tx)//xx == (y-ty)//yy:
index, times = i, (x-tx)//xx
break
if index==-1:
return False
for ob in obstacles:
ox, oy = ob
oidx, otimes = -1, -1
for i in range(len(tmp)):
tx, ty = tmp[i]
if (ox - tx) % xx == 0 and (oy - ty)%yy == 0 and (ox - tx) // xx == (oy - ty) // yy:
oidx, otimes = i, (ox - tx) // xx
break
if oidx!=-1 and otimes!=-1 and (otimes<times or otimes==times and oidx<=index):
return False
return True



print(robot('URR', [[4, 2]],3,2))

标签:tmp,03,LCP,tx,ty,yy,xx,otimes,大冒险
来源: https://www.cnblogs.com/BetterThanEver_Victor/p/16294298.html