Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- class Vector:
- def __init__(self, x, y, z):
- self.x = x
- self.y = y
- self.z = z
- def subtract(self, other):
- return Vector(self.x - other.x,
- self.y - other.y,
- self.z - other.z)
- def __sub__(self, other):
- return self.subtract(other)
- def scalar_multiply(self, other):
- return self.x * other.x + self.y * other.y + self.z * other.z
- def __mul__(self, other):
- return self.scalar_multiply(other)
- def length(self):
- return math.sqrt(self.x * self.x + self.y * self.y + self.z * self.z)
- def vector_multiply(self, other):
- return Vector(self.y * other.z - self.z * other.y,
- self.z * other.x - self.x * other.z,
- self.x * other.y - self.y * other.x)
- def __mod__(self, other):
- return self.vector_multiply(other)
- def cos_between(self, other):
- return self * other / (self.length() * other.length())
- def angle_between(self, other):
- return math.degrees(math.acos(self.cos_between(other)))
- fin = open("input.txt", "r")
- fout = open("output.txt", "w")
- ship_p = Vector(*tuple(map(float, fin.readline().split())))
- keel = Vector(*tuple(map(float, fin.readline().split())))
- mast = Vector(*tuple(map(float, fin.readline().split())))
- enemy_p = Vector(*tuple(map(float, fin.readline().split())))
- cannon_right = keel % Vector(0, 0, 1)
- cannon_left = Vector(0, 0, 1) % keel
- enemy = enemy_p - ship_p
- cannon_angle_left = cannon_left.angle_between(enemy)
- cannon_angle_right = cannon_right.angle_between(enemy)
- if enemy.angle_between(keel) > 90:
- cannon_angle_left *= -1
- cannon_angle_right *= -1
- result = " "
- mast_cannon_angle = 0
- if -60 <= cannon_angle_right <= 60:
- result += "-1\n"
- result += str(round(cannon_angle_right, 2)) + "\n"
- mast_cannon_angle = mast.angle_between(cannon_right)
- elif -60 <= cannon_angle_left <= 60:
- result += "1\n"
- result += str(round(cannon_angle_left, 2)) + "\n"
- mast_cannon_angle = mast.angle_between(cannon_left)
- else:
- result += "0\n"
- mast_angle = mast.angle_between(Vector(0, 0, 1))
- if mast_cannon_angle < 90:
- mast_angle *= -1
- result += str(round(mast_angle, 2)) + "\n"
- result += "This parrot is no more!\n"
- fout.write(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement