Created
July 11, 2014 05:06
-
-
Save cocodrips/1410c998d7311291fce0 to your computer and use it in GitHub Desktop.
SRM627 Div1 Easy
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,string,itertools,fractions,heapq,collections,re,array,bisect, copy | |
class HappyLetterDiv1: | |
def getHappyLetters(self, letters): | |
letters = list(letters) | |
letters.sort() | |
cnt = collections.Counter() | |
for letter in letters: | |
cnt[letter] += 1 | |
result = [] | |
counter = [] | |
for k in cnt.keys(): | |
counter.append([cnt[k], k]) | |
counter.sort(reverse=True) | |
for c in counter: | |
k = c[1] | |
kcounter = copy.deepcopy(counter) | |
index = kcounter.index([cnt[k], k]) | |
target = kcounter.pop(index) | |
if len(kcounter) >= 2: | |
while kcounter[1][0] != 0: | |
kcounter[0][0] -= 1 | |
kcounter[1][0] -= 1 | |
kcounter.sort(reverse=True) | |
summ = 0 | |
for kc in kcounter: | |
summ += kc[0] | |
if summ < target[0]: | |
result.append(k) | |
result.sort() | |
return "".join(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment