叠积木
标题: 叠积木 | 时间限制: 1秒 | 内存限制: 262144K | 语言限制: 不限
有一堆长方体积木,它们的宽度和高度都相同,但长度不一。小橙想把这堆积木叠成一面墙,墙的每层可以放一个积木,也可以将两个积木拼接起来,要求每层的长度相同。若必须用完这些积木,叠成的墙最多为多少层?
一层只能放一块积木或者两块积木
from collections import Counter n = list(map(int, input().split())) c = Counter(n) n1=sorted(set(n),reverse=True) a = [] for i in range(n1[0], 2 * n1[0]): f = 0 for each in n1: if each != i: if c[each] != c[i - each]: f = -1 break else: f += c[each] /2 else: f += c[each] if f != -1: a.append(f) if a: print(int(max(a))) else: print(-1)