SRM 647 Div2 250 PeacefulLine
問題文
TopCoder Statistics - Problem Statement
書いた
class PeacefulLine: def makeLine(self, x): counter = collections.Counter(x) count_arr = [] for word, cnt in counter.most_common(): count_arr.append(cnt) is_continue = True while is_continue: count_arr = sorted(count_arr) count_arr = map(lambda n:n-count_arr[0], count_arr) count_arr = filter(lambda n:n!=0, count_arr) if len(count_arr) <= 1: is_continue = False res = "impossible" if len(count_arr) <= 0 or count_arr[0] <= 1: res = "possible" return res
他の参加者のコード見た
class PeacefulLine: def makeLine(self, x): p = {} l = len(x) if (l%2==0): l=l/2 else: l=(l//2)+1 for i in x: p[i] = p.get(i,0)+1 a = 0 for i in p.keys(): a = max(a,p[i]) if(a>l): return "impossible" else: return "possible"
その他
一番多い数の組が半分以上あればimpossibleだった。
数値の数を数える時に dict.get(i,0)+1
は使えそう