Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. import sys
  2. import math
  3.  
  4. # Auto-generated code below aims at helping you parse
  5. # the standard input according to the problem statement.
  6.  
  7. surface_n = int(input()) # the number of points used to draw the surface of Mars.
  8. map_points = []
  9. for i in range(surface_n):
  10. # land_x: X coordinate of a surface point. (0 to 6999)
  11. # land_y: Y coordinate of a surface point. By linking all the points together in a sequential fashion, you form the surface of Mars.
  12. land_x, land_y = [int(j) for j in input().split()]
  13. map_points.append((land_x, land_y))
  14.  
  15. # identify landing location
  16. diff_points = [(x-compared_x,y-compared_y) for (x,y),(compared_x,compared_y)
  17. in zip(map_points,[(0,0)]+map_points[:-1])]
  18. candidate_areas = [[map_points[index-1],map_points[index]]
  19. for index,(diff_x,diff_y) in enumerate(diff_points)
  20. if diff_x >= 1000 and diff_y == 0]
  21. print('Candidate areas:', candidate_areas, file=sys.stderr)
  22.  
  23.  
  24. def distance(point_a, point_b):
  25. return math.sqrt((point_a[0]-point_b[0])**2+(point_a[1]-point_b[1])**2)
  26.  
  27.  
  28. # game loop
  29. turn = 0
  30. landing_point = (0,0)
  31. GRAVITY = 3.711
  32. VERTICAL_SPEED_LAND_LIMIT = 40
  33. HORIZONTAL_SPEED_LAND_LIMIT = 20
  34. MAX_POWER = 4
  35.  
  36.  
  37. while True:
  38. # h_speed: the horizontal speed (in m/s), can be negative.
  39. # v_speed: the vertical speed (in m/s), can be negative.
  40. # fuel: the quantity of remaining fuel in liters.
  41. # rotate: the rotation angle in degrees (-90 to 90).
  42. # power: the thrust power (0 to 4).
  43. x, y, h_speed, v_speed, fuel, rotate, power = [int(i) for i in input().split()]
  44.  
  45. # Write an action using print
  46. # To debug: print("Debug messages...", file=sys.stderr)
  47. if turn == 0:
  48. landing_points = []
  49. for candidate_points in candidate_areas:
  50. landing_points.append(
  51. ((candidate_points[0][0]+candidate_points[1][0])/2,
  52. (candidate_points[0][1]+candidate_points[1][1])/2))
  53. landing_point = min(landing_points,
  54. key=lambda point: distance(point, (x,y)))
  55. print(landing_point, file=sys.stderr)
  56. vi_x = h_speed
  57. vf_x = HORIZONTAL_SPEED_LAND_LIMIT
  58. a_x = -(vf_x**2-vi_x**2)/(2*(landing_point[0]-x))
  59.  
  60. vi_y = v_speed
  61. vf_y = VERTICAL_SPEED_LAND_LIMIT
  62. a_y = (vf_y**2-vi_y**2)/(2*(landing_point[1]-y))
  63. a_y = a_y+GRAVITY
  64.  
  65. d = math.degrees(math.atan(a_x/a_y))
  66. d = max(min(d,90), -90)
  67.  
  68. a = math.sqrt(a_x**2 + a_y**2)
  69. a = max(min(a,MAX_POWER),0)
  70.  
  71. # rotate power. rotate is the desired rotation angle. power is the desired thrust power.
  72. print(h_speed, v_speed, file=sys.stderr)
  73. print('a_x:', a_x, ',a_y:', a_y, 'deg:', d, file=sys.stderr)
  74. print(round(d),round(a))
  75. turn += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement