Created
November 7, 2013 13:35
-
-
Save cocodrips/7354651 to your computer and use it in GitHub Desktop.
SRM575 Div2 Medium / 二人で勝負をする問題 どちらか一方の立場になって自分が勝つか負けるかmemoしてく
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
class TheNumberGameDivTwo: | |
def find(self, n): | |
if self.rec(n): | |
return 'John' | |
return 'Brus' | |
def rec(self, n, memo={}): | |
if n in memo: | |
return memo[n] | |
memo[n] = self.d(n) | |
return memo[n] | |
def d(self, n): | |
array = [] | |
for i in xrange(2, n): | |
if n % i == 0: | |
array.append(i) | |
if not array: | |
return False | |
for i in array: | |
if not self.rec(n - i): | |
return True | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment