From adb3cc79d469705aa88405c66d75b48ad0d0f988 Mon Sep 17 00:00:00 2001 From: Jethro Stapelbroek Date: Tue, 25 Jul 2023 09:52:50 +0200 Subject: [PATCH] Hitting the Targets --- hittingtargets.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 hittingtargets.py diff --git a/hittingtargets.py b/hittingtargets.py new file mode 100644 index 0000000..ad350bb --- /dev/null +++ b/hittingtargets.py @@ -0,0 +1,32 @@ +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)