蓝桥杯python 基础练习 Huffuman树

每天都要坚持写一下python啊~准备比赛只是一种督促自己好好学习的方式,技术才是硬核呀~~~

蓝桥杯python 基础练习 Huffuman树_第1张图片

经过上一题数列排序的血痕教训,我可长记性啦!限制条件别忘!嗯!没忘!然后......成功通过啦!

# Huffuman树
x = int(input())
if x >= 0 & x <= 100:
    list1 = list(map(int, input().split()))
    list1.sort(reverse=True)
    while list1[0] > 1000:
        del(list1[0])
    total = 0
    while len(list1) > 1:
        list1.sort(reverse=True)
        num = list1.pop()+list1.pop()
        total = total + num
        list1.append(num)
    print(total)

 

你可能感兴趣的:(蓝桥杯,Python)