Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def kangaroo(x1, v1, x2, v2):
- # solve the equations
- # x = x1 + v1*t
- # x = x2 + v2*t
- # you get t = (x1 - x2)/(v2 - v1)
- if v1 == v2: # if they have same speed they can meet only if
- print('YES' if x1 == x2 else 'NO') # they start out together
- else: # otherwise they always meet (possibly in the past, t < 0)
- t = (x1 - x2) // (v2 - v1)
- print('YES' if t >= 0 else 'NO') # but we only want t >= 0
Add Comment
Please, Sign In to add comment