Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import math
- def det_point(l):
- output = []
- curr_x = float(l[0])
- curr_y = float(l[1])
- curr_a = float(l[3])
- for i in range(4,len(l)):
- if l[i] == 'walk':
- steps = float(l[i+1])
- curr_x = round((curr_x + math.cos(math.radians(curr_a%360)) * steps),4)
- curr_y = round((curr_y + math.sin(math.radians(curr_a%360)) * steps),4)
- elif l[i] == 'turn':
- curr_a += float(l[i+1])
- output.append(curr_x)
- output.append(curr_y)
- return output
- def aver(l):
- averages = []
- all_dir = []
- aver_len = len(l)
- x = 0
- y = 0
- for i in l:
- x += i[0]
- y += i[1]
- destination = [round(x*1.0/aver_len,4), round(y/aver_len,4)]
- for i in l:
- ans = round(math.sqrt((i[0] - destination[0])**2 + (i[1] - destination[1])**2),4)
- all_dir.append(ans)
- answer = []
- answer.append(destination)
- answer.append(max(all_dir))
- return answer
- while True:
- input_int = int(sys.stdin.readline())
- if input_int == 0:
- break
- else:
- all_dir = []
- end_points = []
- for i in range(input_int):
- direction = sys.stdin.readline().rstrip().split(" ")
- end_points.append(det_point(direction))
- ans = aver(end_points)
- x = ans[0][0]
- y = ans[0][1]
- z = ans[1]
- if z>0:
- print x,y,z
- else:
- print x,y,0
Add Comment
Please, Sign In to add comment