Skip to content

Instantly share code, notes, and snippets.

@VitamintK
Created May 18, 2019 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VitamintK/bf43a1191f0278ceca2d8cd89ec1fc18 to your computer and use it in GitHub Desktop.
Save VitamintK/bf43a1191f0278ceca2d8cd89ec1fc18 to your computer and use it in GitHub Desktop.
google codejam round 2 2019
T = int(input())
for t in range(T):
n = int(input())
mols = []
for i in range(n):
c, j = map(int, input().split())
mols.append((c,j))
SMALL_NUM = 1/5123456789
slopes = [1+SMALL_NUM, 1-SMALL_NUM]
for i in range(n):
for j in range(i):
a = mols[i]
b = mols[j]
if a[0] == b[0]:
slopes.append(5123456789)
continue
slope = -((a[1]-b[1])/(a[0]-b[0]))
if slope < 0:
continue
slopes.append(slope+SMALL_NUM)
if slope != 0:
slopes.append(slope-SMALL_NUM)
orders = set()
for slope in slopes:
weights = [(mol[0]*slope + mol[1], i) for i, mol in enumerate(mols)]
weights.sort()
# print(slope, tuple(weight[1] for weight in weights), weights)
orders.add(tuple(weight[1] for weight in weights))
ans = len(orders)
#print(orders)
print("Case #{}: {}".format(t+1, ans))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment