360笔试4.2 H卷
第一题主播打赏 ac
n, m = list(map(lambda x:int(x), input().split(" "))) fs_arr = [] for i in range(n): fs_arr.append(list(map(lambda x:int(x), input().split(" ")))) cur_cost = [] all_cost = 0 fs_arr_sum = [0] * m for i in range(n): if i >= 7: cur_cost.pop(0) for j in range(m): fs_arr_sum[j] -= fs_arr[i - 7][j] for j in range(m): fs_arr_sum[j] += fs_arr[i][j] max_v = max(fs_arr_sum) sum_v = sum(cur_cost) if sum_v < max_v: all_cost += (max_v - sum_v + 1) cur_cost.append(max_v - sum_v + 1) else: cur_cost.append(0) print(all_cost)
第二题 组队吃鸡 贪心过9%,回溯提交的时候有bug,笔试完才debug好😅
t = int(input()) def a_match_c(x, y): return min(x, y) def a_match_b(x, y): return min(x // 2, y) def b_match_b(x): return x // 2 def a_match_a(y): return y // 4 for _ in range(t): a, b, c, d = list(map(lambda x: int(x), input().split(" "))) ans = d sub_ans = [] def backtrack(track, a, b, c): if len(methods) == 0: sub_ans.append(track) return for m in methods: if m == a_match_a: tmp = a_match_a(a) a -= tmp * 4 elif m == b_match_b: tmp = b_match_b(b) b -= tmp * 2 elif m == a_match_b: tmp = a_match_b(a, b) a -= tmp * 2 b -= tmp else: tmp = a_match_c(a, c) a -= tmp c -= tmp track += tmp methods.remove(m) backtrack(track, a, b, c) methods.append(m) track -= tmp if m == a_match_a: a += tmp * 4 elif m == b_match_b: b += tmp * 2 elif m == a_match_b: a += tmp * 2 b += tmp else: a += tmp c += tmp methods = [a_match_a, b_match_b, a_match_b, a_match_c] backtrack(0, a, b, c) print(ans + max(sub_ans))