Created
April 22, 2012 20:58
-
-
Save fredrikpaues/2466895 to your computer and use it in GitHub Desktop.
Breaking Eggs
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
import math,sys | |
def main(): | |
if type(sys.stdin).__name__!='file': | |
sys.exit() | |
else: | |
data=[] | |
for line in sys.stdin: | |
data.append(line.strip()) | |
T=int(data[0]) | |
data=data[1:] | |
if len(data)!=T: | |
sys.exit() | |
else: | |
for case in data: | |
values=map(int,case.split(' ')) | |
if len(values)!=2: | |
sys.exit() | |
else: | |
if values[0]<1 or values[0]>300 or values[1]<1 or values[1]>300: | |
sys.exit() | |
else: | |
#Det går väl inte att maximera om vektorn bara innehåller ett element? | |
print max(flatten(process(0,values[0],values[1]))) | |
print 'resultat' | |
def flatten(tree): | |
result=[] | |
for node in tree: | |
try: | |
result.extend(flatten(node)) | |
except TypeError: | |
result.append(node) | |
return result | |
def process(throws,floors,eggs): | |
print int(throws),int(floors),int(eggs) | |
if floors<3 or eggs==1: | |
print 'slutnod' | |
#Har ej anpassats | |
return [int(throws+2+floors)] | |
else: | |
print 'splitt' | |
#Har ej anpassats | |
return [process(throws+2,math.ceil(floors/2)-1+floors%2,eggs-1),process(throws+3,math.floor(floors/2)-1,eggs)] | |
if __name__=='__main__': | |
main() |
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
import sys, BreakingEggs | |
def main(): | |
sys.stdin = open("input03.txt","r") | |
BreakingEggs.main() | |
sys.stdin.close() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment