def find_top_three(strengths):n = len(strengths)players = list(range(n)) # 运动员的编号# 记录每个运动员击败的对手beaten_by = {}for i in range(n):beaten_by[i] = current_round = players.copywhile len(current_round) > 1:next_round = i = 0while i strengths[b]:winner = aloser = belif strengths[a] 1:next_round = current_matches = i = 0while i strengths[b]:winner = aelif strengths[a] strengths[b]:champion = arunner_up = belif strengths[a] = 2:semi_finals = rounds[-2]# 冠军和亚军在半决赛中分别击败了谁champion_semi_opponent = Nonerunner_up_semi_opponent = Nonefor match in semi_finals:a, b = matchif a == champion or b == champion:if a == champion:champion_semi_opponent = belse:champion_semi_opponent = aif a == runner_up or b == runner_up:if a == runner_up:runner_up_semi_opponent = belse:runner_up_semi_opponent = athird_place_candidates = if champion_semi_opponent is not None:third_place_candidates.append(champion_semi_opponent)if runner_up_semi_opponent is not None:third_place_candidates.append(runner_up_semi_opponent)if len(third_place_candidates) == 2:a, b = third_place_candidatesif strengths[a] > strengths[b]:third_place = aelif strengths[a] =3passelse:# 只有一轮比赛,即初始为2人# 季军是剩下的未参赛的人# 但题目保证N >=3,所以初始至少有3人# 所以这种情况不可能passreturn champion, runner_up, third_place# 读取输入strengths = list(map(int, input.split))champion, runner_up, third_place = find_top_three(strengths)print(champion, runner_up, third_place)摘要:def find_top_three(strengths):n = len(strengths)players = list(range(n)) # 运动员的编号# 记录每个运动员击败的对手beaten_by = {}for i in range(n):bea
来源:小贺论科技