Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import math
- # Auto-generated code below aims at helping you parse
- # the standard input according to the problem statement.
- surface_n = int(input()) # the number of points used to draw the surface of Mars.
- map_points = []
- for i in range(surface_n):
- # land_x: X coordinate of a surface point. (0 to 6999)
- # land_y: Y coordinate of a surface point. By linking all the points together in a sequential fashion, you form the surface of Mars.
- land_x, land_y = [int(j) for j in input().split()]
- map_points.append((land_x, land_y))
- # identify landing location
- diff_points = [(x-compared_x,y-compared_y) for (x,y),(compared_x,compared_y)
- in zip(map_points,[(0,0)]+map_points[:-1])]
- candidate_areas = [[map_points[index-1],map_points[index]]
- for index,(diff_x,diff_y) in enumerate(diff_points)
- if diff_x >= 1000 and diff_y == 0]
- print('Candidate areas:', candidate_areas, file=sys.stderr)
- def distance(point_a, point_b):
- return math.sqrt((point_a[0]-point_b[0])**2+(point_a[1]-point_b[1])**2)
- # game loop
- turn = 0
- landing_point = (0,0)
- GRAVITY = 3.711
- VERTICAL_SPEED_LAND_LIMIT = 40
- HORIZONTAL_SPEED_LAND_LIMIT = 20
- MAX_POWER = 4
- while True:
- # h_speed: the horizontal speed (in m/s), can be negative.
- # v_speed: the vertical speed (in m/s), can be negative.
- # fuel: the quantity of remaining fuel in liters.
- # rotate: the rotation angle in degrees (-90 to 90).
- # power: the thrust power (0 to 4).
- x, y, h_speed, v_speed, fuel, rotate, power = [int(i) for i in input().split()]
- # Write an action using print
- # To debug: print("Debug messages...", file=sys.stderr)
- if turn == 0:
- landing_points = []
- for candidate_points in candidate_areas:
- landing_points.append(
- ((candidate_points[0][0]+candidate_points[1][0])/2,
- (candidate_points[0][1]+candidate_points[1][1])/2))
- landing_point = min(landing_points,
- key=lambda point: distance(point, (x,y)))
- print(landing_point, file=sys.stderr)
- vi_x = h_speed
- vf_x = HORIZONTAL_SPEED_LAND_LIMIT
- a_x = -(vf_x**2-vi_x**2)/(2*(landing_point[0]-x))
- vi_y = v_speed
- vf_y = VERTICAL_SPEED_LAND_LIMIT
- a_y = (vf_y**2-vi_y**2)/(2*(landing_point[1]-y))
- a_y = a_y+GRAVITY
- d = math.degrees(math.atan(a_x/a_y))
- d = max(min(d,90), -90)
- a = math.sqrt(a_x**2 + a_y**2)
- a = max(min(a,MAX_POWER),0)
- # rotate power. rotate is the desired rotation angle. power is the desired thrust power.
- print(h_speed, v_speed, file=sys.stderr)
- print('a_x:', a_x, ',a_y:', a_y, 'deg:', d, file=sys.stderr)
- print(round(d),round(a))
- turn += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement