Posted here is the code I've written for wormhole in one. It worked on
every test I ran on it, and it follows the logic of the analysis, and it
still doesnt work.
Can anyone spot the mistake? I would love to know what it was, so I could
fix it the next time, because I can't seem to find any mistake.
(the code is a bit dirty because i've tried some fixes, but it should still
work)
def main():
N = int(input())
holes = []
for i in range(N):
a = [int(x) for x in input().split()]
holes.append(tuple(a))
if N <= 4:
return N
slants = {}
actual_lines = {}
for cur_hole in holes:
for j in holes:
if j == cur_hole:
continue
if cur_hole[0] == j[0]:
slant = 'inf'
else:
slant = float(cur_hole[1] - j[1]) / float(cur_hole[0] -
j[0])
slants.setdefault(slant, [set(), 2])
slants[slant][0].add(cur_hole)
slants[slant][0].add(j)
if slant == 'inf':
y = cur_hole[0]
else:
y = cur_hole[1] - slant * cur_hole[0]
yy = (slant, y)
#actual_lines.setdefault(yy, set([]))
#actual_lines[yy].add(cur_hole)
#actual_lines[yy].add(j)
#for i in actual_lines:
# if len(actual_lines[i]) % 2:
# slants[i[0]][1] ^= 3
a = slants[max(slants, key=lambda x: len(slants[x][0]) +
(len(slants[x][0])%2==0))]
a = len(a[0]) + (len(a[0])%2==0)
return min(N, max(a+1,4))
num_of_cases = [int(x) for x in input().split()][0]
for p in range(num_of_cases):
output = main()
print("Case #{0}: {1}".format(p + 1, output))
--
You received this message because you are subscribed to the Google Groups
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-code/6e4363c0-6b62-4c99-99c2-465f2b29271c%40googlegroups.com.