Created
April 8, 2011 11:00
-
-
Save rainzoo/909641 to your computer and use it in GitHub Desktop.
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
"""Closing the loop | |
http://code.google.com/codejam/contest/dashboard?c=837485#s=p0 | |
""" | |
def nmax(l,n): | |
"""Find sum of n highest numbers from list l | |
""" | |
if l and n <= len(l): | |
temp = l[:] | |
temp.sort() | |
temp.reverse() | |
else: | |
return 0 | |
return sum(temp[:n]) | |
fin = open("A-large-practice.in","r") | |
fout = open("A-large.out","w") | |
cases = int(fin.readline()) | |
counter = cases | |
while(counter > 0): | |
r = [] | |
b = [] | |
n = int(fin.readline()) | |
seg = fin.readline().split() | |
for x in seg: | |
if x[-1:]=='R': | |
r.append(int(x[:-1])) | |
elif x[-1:] == 'B': | |
b.append(int(x[:-1])) | |
l = min(len(r),len(b)) | |
#print n, "r", r, "b", b | |
maxlength = nmax(r,l) + nmax(b,l) - 2*l | |
counter = counter - 1; | |
fout.write("Case #{0}: {1}\n".format(cases-counter, maxlength)) | |
fin.close() | |
fout.close() |
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
"""Investing | |
http://code.google.com/codejam/contest/dashboard?c=837485#s=p1 | |
""" | |
fin = open("B-small-practice.in","r") | |
fout = open("B-small.out","w") | |
cases = int(fin.readline()) | |
counter = cases | |
while(counter > 0): | |
print "\n" | |
money = int(fin.readline()) | |
prices = fin.readline().split() | |
prices = [int(x) for x in prices] | |
b = min(prices[:11]) | |
print "min 1:", b, | |
buy = prices.index(b) | |
if b < money: | |
s = max(prices[buy:]) | |
print "max 1", s | |
if b > s: | |
s = max(prices[1:]) | |
print "Max 2:", s | |
sindex = prices.index(s) | |
b = min(prices[:sindex+1]) | |
print "Min 2:", b | |
units = money / b | |
profit = units * s - money | |
else: | |
profit = "IMPOSSIBLE" | |
if (profit == "IMPOSSIBLE"): | |
fout.write("Case #{0}: {1}\n".format(cases-counter+1, profit)) | |
else: | |
fout.write("Case #{0}: {1} {2} {3}\n".format(cases-counter+1, | |
prices.index(b)+1, | |
prices.index(s)+1, | |
profit)) | |
counter = counter - 1 | |
fin.close() | |
fout.close() |
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
class snapper: | |
def __init__(self): | |
self.p = False | |
self.s = False | |
if __name__ == "__main__": | |
fin = open("A-large-practice.in","r") | |
fout = open("B-small.out","w") | |
cases = int(fin.readline()) | |
counter = cases | |
while(counter > 0): | |
snappers = [] | |
lastState = snapper() | |
prevSnapper = snapper() | |
init = snapper() | |
s1 = snapper() | |
snappers.append(s1) | |
init.p = True | |
s1.p = True | |
line = fin.readline().split() | |
N = int(line[0]) | |
k = int(line[1]) | |
j = k | |
for i in range(1,N): | |
sn = snapper() | |
snappers.append(sn) | |
while (j >= 1): | |
for i,s in enumerate(snappers): | |
if i > 0: | |
lastState.p = s.p | |
lastState.s = s.s | |
s.p = snappers[i-1].s and snappers[i-1].p | |
s.s = lastState.p ^ lastState.s | |
else: | |
s.p = True | |
s.s = not s.s | |
j -= 10 | |
light = snappers[-1].p and snappers[-1].s | |
if light: | |
answer = "ON" | |
else: | |
answer = "OFF" | |
print answer | |
fout.write("Case #{0}: {1}\n".format(cases-counter+1,answer)) | |
counter = counter - 1 | |
fin.close() | |
fout.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment