Guest User

Untitled

a guest
Jul 17th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. import sys
  2. import math
  3. def det_point(l):
  4. output = []
  5. curr_x = float(l[0])
  6. curr_y = float(l[1])
  7. curr_a = float(l[3])
  8. for i in range(4,len(l)):
  9. if l[i] == 'walk':
  10. steps = float(l[i+1])
  11. curr_x = round((curr_x + math.cos(math.radians(curr_a%360)) * steps),4)
  12. curr_y = round((curr_y + math.sin(math.radians(curr_a%360)) * steps),4)
  13. elif l[i] == 'turn':
  14. curr_a += float(l[i+1])
  15.  
  16. output.append(curr_x)
  17. output.append(curr_y)
  18.  
  19. return output
  20.  
  21. def aver(l):
  22. averages = []
  23. all_dir = []
  24. aver_len = len(l)
  25. x = 0
  26. y = 0
  27.  
  28. for i in l:
  29. x += i[0]
  30. y += i[1]
  31.  
  32. destination = [round(x*1.0/aver_len,4), round(y/aver_len,4)]
  33.  
  34.  
  35. for i in l:
  36. ans = round(math.sqrt((i[0] - destination[0])**2 + (i[1] - destination[1])**2),4)
  37. all_dir.append(ans)
  38. answer = []
  39. answer.append(destination)
  40. answer.append(max(all_dir))
  41.  
  42. return answer
  43.  
  44.  
  45.  
  46.  
  47.  
  48. while True:
  49. input_int = int(sys.stdin.readline())
  50. if input_int == 0:
  51. break
  52. else:
  53. all_dir = []
  54. end_points = []
  55. for i in range(input_int):
  56. direction = sys.stdin.readline().rstrip().split(" ")
  57. end_points.append(det_point(direction))
  58. ans = aver(end_points)
  59. x = ans[0][0]
  60. y = ans[0][1]
  61. z = ans[1]
  62. if z>0:
  63. print x,y,z
  64. else:
  65. print x,y,0
Add Comment
Please, Sign In to add comment