Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- import cmath
- enemy = []
- ship = []
- ship_direction = []
- mast_vector = []
- ship_plus_direction = []
- is_left = False
- gun_angle = None
- mast_angle = None
- def read_input():
- file = open('input.txt')
- lines = file.readlines()
- global ship
- ship = [float(i) for i in lines[0].split(' ')]
- global ship_direction
- ship_direction = [float(i) for i in lines[1].split(' ')]
- global mast_vector
- mast_vector = [float(i) for i in lines[2].split(' ')]
- global enemy
- enemy = [float(i) for i in lines[3].split(' ')]
- file.close()
- def mat_sum(x, y):
- c = []
- for i, j in zip(x, y):
- c.append(i+j);
- return c
- def scalar_mult(a, b):
- sum = 0;
- for i, j in zip(a, b):
- sum = sum+i*j
- return sum
- def const_mult(a, b):
- c = []
- for i in a:
- c.append(i*b)
- return c
- def eqv(x, y):
- return (y- ship[1])*(ship_plus_direction[0]- ship[0]) - (x - ship[0])*(ship_plus_direction[1]-ship[1])
- def side():
- def write_answer():
- file = open('output.txt', 'w')
- if abs(gun_angle) > 60:
- file.write('0')
- else:
- if is_left and ship_direction[0]>=0:
- file.write('1'+'\n')
- elif is_left and ship_direction[0] < 0:
- file.write('-1'+'\n')
- elif not is_left and ship_direction[0]>=0:
- file.write('-1'+'\n')
- elif not is_left and ship_direction[0] < 0:
- file.write('1'+'\n')
- file.write(str(gun_angle)+'\n')
- file.write(str(mast_angle)+'\n')
- file.close()
- pass
- def main():
- read_input()
- #
- dist_vector = mat_sum(enemy, const_mult(ship, -1))
- cos_dist_dir = scalar_mult(dist_vector, ship_direction)/(math.sqrt(scalar_mult(dist_vector, dist_vector))*math.sqrt(scalar_mult(ship_direction, ship_direction)))
- global ship_plus_direction
- ship_plus_direction = mat_sum(ship, ship_direction)
- global is_left
- if(eqv(enemy[0], enemy[1])>0):
- is_left = True
- grad_dist_dir = math.acos(cos_dist_dir) * 180./math.pi
- global gun_angle
- gun_angle = 90.-grad_dist_dir
- global mast_angle
- u = [0., 0., 1.]
- mast_angle = math.acos(scalar_mult(u, mast_vector)/(math.sqrt(scalar_mult(u,u))*math.sqrt(scalar_mult(mast_vector, mast_vector))))*180/math.pi
- write_answer()
- pass
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement