Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. import math
  2.  
  3.  
  4. class Vector:
  5. def __init__(self, x, y, z):
  6. self.x = x
  7. self.y = y
  8. self.z = z
  9.  
  10. def subtract(self, other):
  11. return Vector(self.x - other.x,
  12. self.y - other.y,
  13. self.z - other.z)
  14.  
  15. def __sub__(self, other):
  16. return self.subtract(other)
  17.  
  18. def scalar_multiply(self, other):
  19. return self.x * other.x + self.y * other.y + self.z * other.z
  20.  
  21. def __mul__(self, other):
  22. return self.scalar_multiply(other)
  23.  
  24. def length(self):
  25. return math.sqrt(self.x * self.x + self.y * self.y + self.z * self.z)
  26.  
  27. def vector_multiply(self, other):
  28. return Vector(self.y * other.z - self.z * other.y,
  29. self.z * other.x - self.x * other.z,
  30. self.x * other.y - self.y * other.x)
  31.  
  32. def __mod__(self, other):
  33. return self.vector_multiply(other)
  34.  
  35. def cos_between(self, other):
  36. return self * other / (self.length() * other.length())
  37.  
  38. def angle_between(self, other):
  39. return math.degrees(math.acos(self.cos_between(other)))
  40.  
  41.  
  42. fin = open("input.txt", "r")
  43. fout = open("output.txt", "w")
  44.  
  45. ship_p = Vector(*tuple(map(float, fin.readline().split())))
  46. keel = Vector(*tuple(map(float, fin.readline().split())))
  47. mast = Vector(*tuple(map(float, fin.readline().split())))
  48. enemy_p = Vector(*tuple(map(float, fin.readline().split())))
  49.  
  50. cannon_right = keel % Vector(0, 0, 1)
  51. cannon_left = Vector(0, 0, 1) % keel
  52.  
  53. enemy = enemy_p - ship_p
  54.  
  55. cannon_angle_left = cannon_left.angle_between(enemy)
  56. cannon_angle_right = cannon_right.angle_between(enemy)
  57.  
  58. if enemy.angle_between(keel) > 90:
  59. cannon_angle_left *= -1
  60. cannon_angle_right *= -1
  61.  
  62. result = " "
  63. mast_cannon_angle = 0
  64.  
  65. if -60 <= cannon_angle_right <= 60:
  66. result += "-1\n"
  67. result += str(round(cannon_angle_right, 2)) + "\n"
  68.  
  69. mast_cannon_angle = mast.angle_between(cannon_right)
  70. elif -60 <= cannon_angle_left <= 60:
  71. result += "1\n"
  72. result += str(round(cannon_angle_left, 2)) + "\n"
  73.  
  74. mast_cannon_angle = mast.angle_between(cannon_left)
  75. else:
  76. result += "0\n"
  77.  
  78. mast_angle = mast.angle_between(Vector(0, 0, 1))
  79. if mast_cannon_angle < 90:
  80. mast_angle *= -1
  81.  
  82. result += str(round(mast_angle, 2)) + "\n"
  83.  
  84. result += "This parrot is no more!\n"
  85.  
  86. fout.write(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement