Created
December 27, 2018 06:18
-
-
Save bricakeld/26a5ecedda8de54845f62ddb20554163 to your computer and use it in GitHub Desktop.
Kattis Foosball Solution in Python
This file contains hidden or 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
# I mainly use c++ to solve the problems but I use mainly Python in my school, so I thought I'd give Python a try in such problems | |
# Python3 | |
import sys | |
import collections | |
n = int(sys.stdin.readline()) | |
in_names = sys.stdin.readline().split() | |
output = [] | |
curr_max = 1 | |
scores = [[0]*n for i in range(n)] | |
q = collections.deque() | |
white_off = 0 | |
black_off = 1 | |
white_def = 2 | |
black_def = 3 | |
for i in range(4, n): | |
q.append(i) | |
games = sys.stdin.readline() | |
prev = games[0] | |
indices =set() | |
counter = 1 | |
start_i = 0 | |
indices.add(0) | |
games = games.strip() | |
for i, g in enumerate(games[1:], start=1): | |
if g == prev: | |
counter += 1 | |
else: | |
start_i = i | |
counter = 1 | |
if counter > curr_max: | |
curr_max = counter | |
indices.clear() | |
indices.add(start_i) | |
elif counter == curr_max: | |
indices.add(start_i) | |
prev = g | |
if 0 in indices: | |
if games[0] == 'W': | |
output.append((white_off, white_def)) | |
if games[0] == 'B': | |
output.append((black_off, black_def)) | |
indices.remove(0) | |
for i, g in enumerate(games): | |
if g == 'W': | |
if i in indices: | |
output.append((white_def, white_off)) | |
white_off, white_def = white_def, white_off | |
q.append(black_def) | |
black_def = black_off | |
black_off = q.popleft() | |
else: | |
if i in indices: | |
output.append((black_def, black_off)) | |
black_off, black_def = black_def, black_off | |
q.append(white_def) | |
white_def = white_off | |
white_off = q.popleft() | |
for o in output: | |
sys.stdout.write(in_names[o[0]] + " " + in_names[o[1]] + "\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment