网易游戏数据挖掘研究员编程题题解
1. Adaboost二分类 AC
from math import log,exp while True: try: m, n, k = list(map(int, input().split())) train_label = list(map(int, input().split())) y_train = [[0 for i in range(n)] for j in range(m)] for i in range(m): y_train[i] = list(map(int, input().split())) y_test = [[0 for i in range(m)] for j in range(k)] for i in range(k): y_test[i] = list(map(int, input().split())) weight = [1/n] * n w = [] for i in range(m): error = 0 for j in range(n): if train_label[j] != y_train[i][j]: error += weight[j] if error == 0: a = 1 elif error == 1: a = 0 else: a = (log(1 - error) - log(error)) / 2 w.append(a) z = 0 for j in range(n): z += weight[j] * exp(- a * train_label[j] * y_train[i][j]) for j in range(n): weight[j] = weight[j] * exp(- a * train_label[j] * y_train[i][j]) / z for i in range(k): f = 0 for j in range(m): f += y_test[i][j] * w[j] if f >= 0: print(1) else: print(-1) except: break
2. 技能加点 AC
while True: try: n, m = list(map(int, input().split())) p = list(map(int, input().split())) l = [0] * (m + 1) l[0] = 1 for i in range(n): for j in range(p[i], m + 1): l[j] = l[j] + l[j - p[i]] print(l[-1]) except: break
3. 实现一个SQL语句的输出 0.4 TLE
while True: try: n = int(input()) data = [[0 for i in range(4)] for j in range(n)] for i in range(n): data[i] = list(map(int, input().split())) Id = [item[0] for item in data] age = [item[1] for item in data] height = [item[2] for item in data] weight = [item[3] for item in data] value = [[0 for i in range(n)] for j in range(n)] for i in range(n): for j in range(n): if j == i: pass elif j > i: value[i][j] = round(((age[i] - age[j]) ** 2 + (height[i] - height[j]) ** 2 + (weight[i] - weight[j]) ** 2) ** (1/2),2) else: value[i][j] = value[j][i] cur_id = 0 cur_min = float('inf') for j in range(n): if j == i: pass else: if value[i][j] < cur_min: cur_min = value[i][j] cur_id = j if cur_min < 20: res = [Id[i], Id[cur_id], cur_min] res[-1] = '%.2f' % res[-1] print(' '.join(list(map(str, res)))) except: break
#网易##数据挖掘##题解#