Skip to content

Commit

Permalink
add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
zehengl committed Aug 27, 2024
1 parent 8a37beb commit ae51d7e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/beehives.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
def dist2(b1, b2):
return (b1[0] - b2[0]) ** 2 + (b1[1] - b2[1]) ** 2


while True:
d, n = input().split()
d = float(d)
n = int(n)
if not d and not n:
break
b = []
for _ in range(n):
x, y = [float(v) for v in input().split()]
b.append((x, y))
b = sorted(b, key=lambda v: (v[0], v[1]))

sour = set()

for i in range(len(b)):
if len(sour) == n:
break
for j in range(i + 1, len(b)):
if len(sour) == n:
break
if dist2(b[i], b[j]) < d**2:
sour.add(i)
sour.add(j)

nsour = len(sour)
nsweet = n - nsour
print(f"{nsour} sour, {nsweet} sweet")
11 changes: 11 additions & 0 deletions src/hofundaleit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
n, q = [int(d) for d in input().split()]
b = []
for _ in range(n):
t, a = input().split(", ")
b.append((t, a))

b = dict(zip([t for t, _ in sorted(b, key=lambda v: (v[1], v[0]))], range(1, n + 1)))

for _ in range(q):
t = input()
print(b.get(t, -1))

0 comments on commit ae51d7e

Please sign in to comment.