dead_men_shot.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. '''
  2. @author: olivier.massot, 2019
  3. '''
  4. shape = [tuple([int(j) for j in input().split()]) for _ in range(int(input()))]
  5. shots = [tuple([int(j) for j in input().split()]) for _ in range(int(input()))]
  6. xmin, xmax = min([c[0] for c in shape]), max([c[0] for c in shape])
  7. edges = list(zip(shape[:-1], shape[1:])) + [(shape[-1], shape[0])]
  8. oedges = [sorted(e, key=lambda x: x[0]) for e in edges]
  9. def is_in(xs, ys):
  10. if not xmin <= xs <= xmax:
  11. return False
  12. fx = []
  13. for start, end in oedges:
  14. # vertical edge
  15. if start[0] == end[0]:
  16. if xs == start[0] and start[1] <= ys <= end[1]:
  17. return True
  18. else:
  19. continue
  20. if start[0] <= xs <= end[0]:
  21. a = (end[1] - start[1]) / (end[0] - start[0])
  22. b = -1 * a * end[0] + end[1]
  23. fx.append(a * xs + b)
  24. fx = sorted(list(set(fx)))
  25. for y0, y1 in zip(fx[:-1:2], fx[1::2]):
  26. if y0 <= ys <= y1:
  27. return True
  28. return False
  29. for s in shots:
  30. print("hit" if is_in(*s) else "miss")