网易8.21算法笔试
1、算法题
1)找中位数 ac66.7% 啊我觉得我是个*** 还提前半个小时交卷 着急去吃饭啊 这么简单的题我都没过 复盘的时候发现是减号写成加号了 再也不提前交卷了o(╥﹏╥)o
def median(arr): # write code here if len(arr) <= 1: return arr[0] if len(arr) == 2: return (arr[0] + arr[1]) / 2 arr.sort() mid = len(arr) // 2 if len(arr) % 2 == 1: return arr[mid] else: return (arr[mid] + arr[mid - 1]) / 2 arr = [2,3,4,5] print(median(arr))2)匹配字符串 ac80%
import sys
if __name__ == '__main__':
name_lst = sys.stdin.readline().strip().split(' ')
text = sys.stdin.readline().strip()
count = 0
for name in name_lst:
count += text.count(name)
print(count)
3)二分类计算softmax 全ac
import math
import sys
if __name__ == '__main__':
line1 = sys.stdin.readline().strip().split(' ')
N = int(line1[0])
K = int(line1[1])
logits_lst = []
for i in range(N):
lst = sys.stdin.readline().strip().split(' ')
logits_lst.append([float(x) for x in lst])
for i in range(N):
line_max = max(logits_lst[i])
index = logits_lst[i].index(line_max)
fenmu = 0
for num in logits_lst[i]:
fenmu += math.exp(num)
fenzi = math.exp(line_max)
p = round(fenzi/fenmu,6)
print(index,' ',p)
4)小朋友发纸 ac70%
import sys
if __name__ == '__main__':
line = sys.stdin.readline().strip().split(' ')
years_lst = [int(x) for x in line]
paper_count = 1
total_count = 1
for i in range(1,len(years_lst)):
if years_lst[i] > years_lst[i-1]:
paper_count += 1
elif years_lst[i] == years_lst[i-1]:
if paper_count != 1:
paper_count -= 1
total_count += paper_count
print(total_count)
2、问答题
1)什么是欠拟合什么是过拟合?2)在模型训练过程中如何判断欠拟合过拟合?3)如何解决欠拟合过拟合?
#网易笔试##笔经##算法工程师#
查看12道真题和解析