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 LittleElephantAndDouble: | |
| def getAnswer(self, A): | |
| m = max(A) | |
| for a in A: | |
| if not self.doubleUntilM(a, m): | |
| return 'NO' | |
| return 'YES' | |
| def doubleUntilM(self, a, m): | |
| print(a, m) |
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 LittleElephantAndString: | |
| def getNumber(self, A, B): | |
| if sorted(A) != sorted(B): | |
| return -1 | |
| A = list(A)[::-1] | |
| B = list(B)[::-1] | |
| non_move = 0 | |
| a_index = 0 |
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
| def calculate_distance_fast(self, src_name, dst_name): | |
| self.reset() | |
| src = self.get_node_from_name(src_name) | |
| dst = self.get_node_from_name(dst_name) | |
| src.visited = True | |
| queue1 = Queue.Queue() | |
| queue1.put(src) | |
| queue2 = Queue.Queue() | |
| queue2.put(dst) |
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 | |
| def primetable(max): | |
| sq = math.sqrt(max) | |
| table = [] | |
| t = range(0, max+1) | |
| t[0] = 0 | |
| t[1] = 0 | |
| p = 2 |
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
| def solve(before, after): | |
| pairs_dict = {} | |
| for i in xrange(len(before)): | |
| if not pairs_dict.has_key(before[i]): | |
| pairs_dict[before[i]] = after[i] | |
| else: | |
| if pairs_dict[before[i]] != after[i]: | |
| return "impossible" | |
| if len(pairs_dict) >= 26: |
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 ORSolitaireDiv2: | |
| def getMinimum(self, numbers, goal): | |
| numbers = list(numbers) | |
| numbers.sort() | |
| goal_bin = str(bin(goal))[2:] | |
| goal_bin = list(reversed(goal_bin)) | |
| counter = [0 for _ in goal_bin] | |
| numbers = [num for num in numbers if num <= goal] |
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 TheShuttles: | |
| def getLeastCost(self, cnt, baseCost, seatCost): | |
| cnt = list(cnt) | |
| m = max(cnt) | |
| mini = 100000000000 | |
| for i in xrange(1, m + 1): | |
| sum = 0 | |
| for c in cnt: | |
| sum += (baseCost + (seatCost * i)) * math.ceil(float(c) / i) |
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
| def solve(data): | |
| data = sorted(data) | |
| sets = 0 | |
| p = data[:len(data) / 2] | |
| n = data[len(data) / 2:] | |
| pi = len(p) - 1 | |
| ni = len(n) - 1 | |
| while pi >= 0: |
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 | |
| def prime_decomposition(n): | |
| array = [] | |
| primes = primetable(int(math.ceil(math.sqrt(n)))) | |
| while n > 1: | |
| for p in primes: | |
| if n % p == 0: | |
| n /= p | |
| array.append(p) | |
| break |
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 collections | |
| import math | |
| class BigFatInteger2: | |
| def isDivisible(self, A, B, C, D): | |
| As = self._prime_decomposition(A) | |
| Cs = self._prime_decomposition(C) | |
| print As, Cs | |
| for c in set(Cs): |