Last active
December 12, 2015 13:12
-
-
Save cjhanks/d64ceeb369ee8571c56e to your computer and use it in GitHub Desktop.
CodeJam Stuff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import stdin | |
def compute(A, B): | |
A.sort(reverse=True) | |
B.sort(reverse=False) | |
return sum(i * j for i, j in zip(A, B)) | |
test_cases = int(next(stdin)) | |
for case in range(test_cases): | |
_ = next(stdin) | |
lineA = map(float, next(stdin).strip().split(' ')) | |
lineB = map(float, next(stdin).strip().split(' ')) | |
print('Case #%d: %d' % (case + 1, compute(lineA, lineB))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import namedtuple | |
from sys import stdin | |
from itertools import count | |
LineEquation = \ | |
namedtuple('LineEquation', | |
[ | |
'A', | |
'C' | |
]) | |
def lines_intersect(i, j): | |
if i.A == j.A: | |
return False | |
intersect = (j.C - i.C) / (i.A - j.A) | |
return 0 < intersect < 1 | |
# -- | |
def make_line(pt0, pt1): | |
return LineEquation(float(pt1 - pt0), pt0) | |
def test(lines): | |
intersections = 0 | |
for i in range(len(lines)): | |
for j in range(i + 1, len(lines)): | |
if lines_intersect(lines[i], lines[j]): | |
intersections += 1 | |
return intersections | |
test_cases = int(next(stdin)) | |
for case in range(test_cases): | |
try: | |
points = int(next(stdin)) | |
except StopIteration: | |
break | |
lines = [] | |
for i in range(points): | |
data = next(stdin).strip().split(' ') | |
lines.append(make_line(int(data[0]), int(data[1]))) | |
print('Case #%d: %d' % (case + 1, test(lines))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import stdin | |
def add_path(root, path): | |
count = 0 | |
path_array = path.lstrip('/').split('/') | |
for link in path_array: | |
if not link in root: | |
count += 1 | |
root[link] = {} | |
root = root[link] | |
return count | |
cases = int(next(stdin)) | |
for case in range(cases): | |
exist, tests = map(int, next(stdin).split(' ')) | |
root = {} | |
for i in range(exist): | |
add_path(root, next(stdin).strip()) | |
count = 0 | |
for i in range(tests): | |
count += add_path(root, next(stdin).strip()) | |
print('Case #%d: %d' % (case + 1, count)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment