Say we have a tournament of some sort. It doesn’t really matter what the tournament is for; all we need to know is that each game in the tournament is 1:1.
At the end of a game, each player has a non-negative score (0 or higher). We’ll use the usual rules of higher score wins, and it’s perfectly possible that a game results in a tie.
To keep things fair, at the end of the tournament, everybody has played the same number of games.
Given the results of a tournament and the IDs of two players, we’d like to know which of those two players did better in the overall tournament.
Game results are in the format {player1, score1, player2, score2}.
If Alice and Bob finish the tournament with the same record, but Alice played Bob and won, then we say that Alice did better than Bob overall.
这道题的核心是比较锦标赛中两位选手的整体表现。每场比赛是 1 对 1,分数高者获胜,平局也可能出现;所有选手比赛场次相同,因此可以先根据每一场比赛统计每个选手的胜负平记录,再比较两位目标选手的总战绩。如果总战绩相同,还要检查这两人是否曾直接交手,并把直接对战的胜者视为整体表现更好的一方。实现时通常用哈希表记录每个 player 的胜负信息,再遍历结果数组完成统计,时间复杂度为线性。