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))


#360笔试##春招##笔试题目##Python#
全部评论
第二题贪心能ac,考率1—3组合,然后2单独组合,然后1—2组合,最后1组合,我这样写可以ac
2 回复 分享
发布于 2022-04-02 17:32
第一题感觉思路和你差不多,只过了36%,不知道为啥
点赞 回复 分享
发布于 2022-04-03 06:36
为啥我第二题是最小声成熟
点赞 回复 分享
发布于 2022-04-02 17:39

相关推荐

昨天 18:45
已编辑
中山职业技术学院 Java
投递TP-LINK等公司7个岗位
点赞 评论 收藏
分享
评论
3
10
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务