# Define a recursive depth-first search function. # Marks nodes on the graph in alternating 'colors.' def bipartite_dfs(graph, start, alternator, visited=None): if visited is None: visited = set() global colors colors = list([set(), set()]) colors[1 - alternator].add(start) visited.add(start) for node in graph[start]: colors[alternator].add(node) if node not in visited: bipartite_dfs(graph, node, 1 - alternator, visited) return colors problem = GCJManager(6234486, 0, 0) # Main per-case logic goes here: for case in range(int(problem.input())): # Begin each case by setting up a graph implemented as a dictionary. pairs = list() names = set() league_graph = dict() for line in range(int(problem.input())): pair = problem.input().split() pairs.append(pair) names.add(pair[0]) names.add(pair[1]) for name in names: league_graph[name] = set() for pair in pairs: league_graph[pair[0]].add(pair[1])
""" Author: Jeff Sell Solution to Google Code Challenge practice problem "Store Credit" https://code.google.com/codejam/contest/351101/dashboard#s=p0 This solution makes use of GCJManager. https://github.com/jtsell/GCJManager """ from gcjmanager import GCJManager from pairing import Pairing problem = GCJManager(351101, 0, 0) for case in range(0, int(problem.input())): Credit = problem.input() Items = problem.input() Prices = problem.input() myPairing = Pairing(Credit, Items, Prices) answer = myPairing.getPair() problem.output('{} {}'.format(answer[0], answer[1])) message = problem.finish() print(message)
""" Author: Jeff Sell Solution to Google Code Challenge "Captain Hammer" https://code.google.com/codejam/contest/6234486/dashboard#s=p1 Makes use of GCJManager, available at: https://github.com/jtsell/GCJManager """ from gcjmanager import GCJManager from math import asin, pi problem = GCJManager(6234486, 1, 0) g = 9.8 for case in range(int(problem.input())): v, d = problem.input().split() v = int(v) d = int(d) # Ugly hack to resolve floating point imprecision causing domain error: x = (d * g) / v ** 2 if x > 1: x = 1 # /Ugly hack. theta = asin(x) * (90 / pi) problem.output(str(theta)) msg = problem.finish() print(msg)