frederick99

kangaroo

Jun 22nd, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. def kangaroo(x1, v1, x2, v2):
  2.     # solve the equations
  3.     # x = x1 + v1*t
  4.     # x = x2 + v2*t
  5.     # you get t = (x1 - x2)/(v2 - v1)
  6.  
  7.     if v1 == v2:    # if they have same speed they can meet only if
  8.         print('YES' if x1 == x2 else 'NO')  # they start out together
  9.     else:       # otherwise they always meet (possibly in the past, t < 0)
  10.         t = (x1 - x2) // (v2 - v1)
  11.         print('YES' if t >= 0 else 'NO') # but we only want t >= 0
Add Comment
Please, Sign In to add comment