Files
kattis/hittingtargets.py

33 lines
867 B
Python

def isInsideCircle(cx, cy, r, x, y):
dist = (x - cx) ** 2 + (y - cy) ** 2
return dist <= r**2
def isInsideRectangle(rx1, ry1, rx2, ry2, x, y):
return (rx1 <= x <= rx2) and (ry1 <= y <= ry2)
targets = []
for _ in range(int(input())):
t = input().split()
if t[0] == "rectangle":
targets.append(["R", int(t[1]), int(t[2]), int(t[3]), int(t[4])])
else:
targets.append(["C", int(t[1]), int(t[2]), int(t[3])])
for _ in range(int(input())):
x, y = map(int, input().split())
hits = 0
for target in targets:
if target[0] == "R":
hits += (
1
if isInsideRectangle(target[1], target[2], target[3], target[4], x, y)
else 0
)
else:
hits += 1 if isInsideCircle(target[1], target[2], target[3], x, y) else 0
print(hits)