b.FightingZombies.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import numpy as np
  2. class Plate:
  3. def __init__(self, h, s, z):
  4. self.height = []
  5. self.space = s
  6. self.zombies = z
  7. def addToPlates(plates, R, i, x, y):
  8. print(plates)
  9. newSpace = [x-R/2, x+R/2, y+R/2, y-R/2]
  10. newPlate = Plate(1, newSpace, [i])
  11. toAdd = []
  12. for p in plates:
  13. if newSpace[0] <= p.space[1] and newSpace[1] >= p.space[0] and newSpace[2] > p.space[3] and newSpace[3] < p.space[2]:
  14. # Overlap
  15. overlapSpace = [max(newSpace[0], p.space[0]), min(newSpace[1], p.space[1]), min(newSpace[2], p.space[2]), max(newSpace[3], p.space[3])]
  16. print(p.zombies)
  17. overlapPlate = Plate(newPlate.height + p.height, overlapSpace, p.zombies.extend(newPlate.zombies))
  18. toAdd.append(overlapPlate)
  19. plates.append(newPlate)
  20. plates.extend(toAdd)
  21. def solve(N, R, XY):
  22. # print("N={0}, R={1}, XY={2}".format(N, R, XY))
  23. # Create plates
  24. plates = []
  25. for i, xy in enumerate(XY):
  26. x, y = xy
  27. addToPlates(plates, R, i, x, y)
  28. print(plates)
  29. return 'white'
  30. if __name__ == "__main__":
  31. import fileinput
  32. f = fileinput.input()
  33. T = int(f.readline())
  34. for case in range(1, T+1):
  35. N, R = [int(i) for i in f.readline().split()]
  36. XY = [[int(i) for i in f.readline().split()] for x in range(N)]
  37. solution = solve(N, R, XY)
  38. print("Case #{0}: {1}".format(case, solution))