21农行软开(天津),秋招第二批笔经
题型结构和数量都与实习一样,不赘述。
主要复现一下编程题吧
一、二进制回文数
x=bin(num) res=x[2:] if res==res[::-1]: return 1 else: return 0
二、巨型天平:给定6人体重,平均分两组,看能否是天平平衡
x=sum(weights) list1=[[]] for i in range(len(weights)): for j in range(len(list1)): sub=list1[j]+[weights[i]] if sub not in weights: list1.append(sub) res=0 for k in list1: if len(k)==3 and sum(k)==x/2: res=1 break return res
三、ABCD四种字符组成的序列,随机选择一个字符,确定其信息量(香农信息熵)
import math
list1=list(content)
a=list.count('A')
b=list.count('B')
c=list.count('C')
d=list.count('D')
a1=a/len(content)
b1=b/len(content)
c1=c/len(content)
d1=d/len(content)
if a1==0:
a2=0
else:
a2=a1*math.log(a1,2)
if b1==0:
b2=0
else:
b2=b1*math.log(b1,2)
if c1==0:
c2=0
else:
c2=c1*math.log(c1,2)
if d1==0:
d2=0
else:
d2=d1*math.log(d1,2)
h=-(a2+b2+c2+d2)
return h - 回忆版,可能记得不太清楚,见谅~
查看22道真题和解析