Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.51 KB | None | 0 0
  1. import math
  2.  
  3. inp = open('input.txt', 'r')
  4. otp = open('output.txt', 'w')
  5.  
  6. strinp = inp.readline()  # Where is my boat
  7. Ux, Uy = map(float, strinp.split())
  8. strinp = inp.readline()  # Direction of my boat (vec a)
  9. ax, ay = map(float, strinp.split())
  10. strinp = inp.readline()  # Direction of my 'mach'
  11. mx, my = map(float, strinp.split())
  12. strinp = inp.readline()  # Where empty boats are
  13. wx, wy = map(float, strinp.split())
  14.  
  15. corner_of_enemies = 90 - math.acos((ax * (wx - Ux) + ay * (wy - Uy)) / ((ax**2 + ay**2)**0.5 * ((wx - Ux)**2 + (wy - Uy)**2)**0.5))*180/math.pi
  16.  
  17. corner_of_mach = abs(math.acos(1 / ((mx**2 + my**2 + 1)**0.5)) * 180 / math.pi)
  18. if mx*(ay-Uy) - my*(ax-Ux) > 0:
  19.     corner_of_mach *= -1
  20.  
  21. orientation = 0
  22. if ax == 0:
  23.     if wx < ax+Ux:
  24.         if ay > 0:
  25.             orientation = 1
  26.         else:
  27.             orientation = -1
  28.     elif wx > ax+Ux:
  29.         if ay > 0:
  30.             orientation = -1
  31.         else:
  32.             orientation = 1
  33. elif wy > (((ax+Ux)*Uy - (ay+Uy)*Ux)+((ay+Uy) - Uy)*wx) / ax:
  34.     if ax > 0:
  35.         orientation = 1
  36.     else:
  37.         orientation = -1
  38. elif wy < (((ax+Ux)*Uy - (ay+Uy)*Ux)+((ay+Uy) - Uy)*wx) / ax:
  39.     if ax > 0:
  40.         orientation = -1
  41.     else:
  42.         orientation = 1
  43.  
  44.  
  45. if abs(corner_of_enemies) < 60 and abs(corner_of_mach) < 60 and orientation != 0:
  46.     otp.write(str(orientation) + '\n')
  47.     otp.write(str(round(corner_of_enemies, 2)) + '\n')
  48.     otp.write(str(round(corner_of_mach, 2)) + '\n')
  49.     otp.write('Ahtung!')
  50. else:
  51.     otp.write('0')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement