Skip to content

Instantly share code, notes, and snippets.

@huffman
Created September 20, 2012 03:39
Show Gist options
  • Save huffman/3753839 to your computer and use it in GitHub Desktop.
Save huffman/3753839 to your computer and use it in GitHub Desktop.
GCJ 2008 Qualification
#!/usr/bin/env python
from sys import stdin
from sets import Set
for case in xrange(int(stdin.readline())):
num_engines = int(stdin.readline())
engines = []
for _ in xrange(num_engines):
engines.append(stdin.readline())
seq_set = Set([])
min_switches = 0
for _ in xrange(int(stdin.readline())):
query = stdin.readline()
seq_set.add(query)
if len(seq_set) == num_engines:
seq_set = Set([query])
min_switches += 1
print 'Case #%i: %i' % (case + 1, min_switches)
@alts
Copy link

alts commented Sep 20, 2012

sets exist in the main namespace

seq_set = set() # no empty list required. it's the same if omitted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment