Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.36 KB | None | 0 0
  1. import math
  2. import cmath
  3.  
  4. enemy = []
  5. ship = []
  6. ship_direction = []
  7. mast_vector = []
  8. ship_plus_direction = []
  9. is_left = False
  10. gun_angle = None
  11. mast_angle = None
  12.  
  13.  
  14. def read_input():
  15.     file = open('input.txt')
  16.     lines = file.readlines()
  17.     global ship
  18.     ship = [float(i) for i in lines[0].split(' ')]
  19.     global ship_direction
  20.     ship_direction = [float(i) for i in lines[1].split(' ')]
  21.     global mast_vector
  22.     mast_vector = [float(i) for i in lines[2].split(' ')]
  23.     global enemy
  24.     enemy = [float(i) for i in lines[3].split(' ')]
  25.     file.close()
  26.  
  27. def mat_sum(x, y):
  28.     c = []
  29.     for i, j in zip(x, y):
  30.         c.append(i+j);
  31.     return c
  32.  
  33. def scalar_mult(a, b):
  34.     sum = 0;
  35.     for i, j in zip(a, b):
  36.         sum = sum+i*j
  37.     return sum
  38.  
  39. def const_mult(a, b):
  40.     c = []
  41.     for i in a:
  42.         c.append(i*b)
  43.     return c
  44.  
  45. def eqv(x, y):
  46.     return (y- ship[1])*(ship_plus_direction[0]- ship[0]) - (x - ship[0])*(ship_plus_direction[1]-ship[1])
  47.  
  48. def side():
  49.    
  50.  
  51. def write_answer():
  52.     file = open('output.txt', 'w')
  53.     if abs(gun_angle) > 60:
  54.         file.write('0')
  55.     else:
  56.         if is_left and ship_direction[0]>=0:
  57.             file.write('1'+'\n')
  58.         elif is_left and ship_direction[0] < 0:
  59.             file.write('-1'+'\n')
  60.         elif not is_left and ship_direction[0]>=0:
  61.             file.write('-1'+'\n')
  62.         elif not is_left and ship_direction[0] < 0:
  63.             file.write('1'+'\n')
  64.         file.write(str(gun_angle)+'\n')
  65.         file.write(str(mast_angle)+'\n')
  66.     file.close()
  67.     pass
  68.  
  69. def main():
  70.     read_input()
  71.     #
  72.     dist_vector = mat_sum(enemy, const_mult(ship, -1))
  73.     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)))
  74.     global ship_plus_direction
  75.     ship_plus_direction = mat_sum(ship, ship_direction)
  76.     global is_left
  77.     if(eqv(enemy[0], enemy[1])>0):
  78.         is_left = True
  79.     grad_dist_dir = math.acos(cos_dist_dir) * 180./math.pi
  80.     global gun_angle
  81.     gun_angle = 90.-grad_dist_dir
  82.     global mast_angle
  83.     u = [0., 0., 1.]
  84.     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
  85.     write_answer()
  86.     pass
  87.  
  88.  
  89. if __name__ == '__main__':
  90.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement