【问题标题】:Sort algorithm between multiple items and not just between two items (basketball)?多个项目之间的排序算法,而不仅仅是两个项目(篮球)之间的排序算法?
【发布时间】:2011-11-17 22:03:05
【问题描述】:

我们需要对篮球队进行分类。

流程参考如下:

D.1 Procedure
Teams shall be classified according to their win-loss records, namely two (2) points
for each game won, one (1) point for each game lost (including lost by default) and
zero (0) points for a game lost by forfeit.

D.1.1 If there are two (2) teams in the classification with equal points, the result(s) of the
game(s) between the two (2) teams involved will be used to determine the placing.

D.1.2 If the points and the goal average in the games between the two (2) teams are still
the same, the classification will be determined by the goal average of all the games
played in the group by each team.

D.1.3 If there are more than two (2) teams in the classification with equal points, a second
classification will be established, taking into account only the results of the games
between the involved teams.

D.1.4 If at any stage of this procedure the number of teams with equal points is reduced
to only two (2) teams, the procedure in D.1.1 and D.1.2 above will be applied.

D.1.5 If in the second classification there are still teams with equal points, the goal
average will be used to determine the placing, taking into account only the results
of the games between the involved teams.

D.1.6 If there are still more than two (2) teams with the same goal average, the placing
will be determined using the goal average from the results of all their games played
in the group.

D.1.7 If at any stage of this procedure the number of teams with equal points is reduced
to a tie still involving more than two (2) teams, the procedure, beginning with D.1.3
above, is repeated.

D.1.8 Goal average will always be calculated by division.

问题是如何处理 D.1.3 部分,其中说:If there are more than two (2) teams in the classification with equal points, a second classification will be established, taking into account only the results of the games between the involved teams. 如何对第二个分类进行建模以及如何根据它们之间的博弈结果做出决定?

【问题讨论】:

  • 当只有 1.3 部分重要时,您真的需要几乎逐字逐句发布问题吗?

标签: java php algorithm sorting data-structures


【解决方案1】:

对于得分相等的 k 支球队,构建一个较小的“联赛表”,大小为 k,将仅根据这些球队之间的比赛来填充分数和目标。

在这个较小的表上递归激活排名过程。

如果在 2 次递归调用之间没有减少团队 [团队完全相等] 或建立完整排名,则暂停。如果列表仅包含两个得分相同的团队:次要标准适用。

【讨论】:

    【解决方案2】:

    您的比较器可以参考团队列表。即使在调用过程 D.1.3 的情况下,它也能够比较这两个元素。

    【讨论】:

    • 这似乎是最初的方式,但转念一想,我认为你让自己陷入了麻烦:这不是像“使用字段 a 并且如果相等则使用字段 b”这样的情况 - 而是字段“b”(性能与直接竞争对手)需要按需计算。您要么必须在每次评估该组的成员时重新计算它,要么预先计算它。如果您确实有平局,您只想预先计算它。所以你必须先按第一个标准排序。这让您有效地使用@missingno 的解决方案
    • 正确。您可以将比较结果存储在 Comparator 中以避免不必要的重新计算,但这基本上是missingno 的解决方案。这种方法的主要优点是,一旦你对 Comparator 进行了编程,你就可以将它传递给 Collections.sort。
    【解决方案3】:

    按照你在现实生活中的做法:

    1. 使用标准列表对团队进行排序以进行比较
    2. 列表排序后,对其进行传递,看看是否有 3 支以上的球队并列。
    3. 每当您发现这样一组超过 3 条关系时,这次使用不同的设置标准解决它。

    【讨论】:

      【解决方案4】:

      您可以为此使用BogoSort

      1. 将所有团队存储在一个列表中。
      2. 创建一个验证器,用于确定List<Team> 是否按照程序正确排序。
      3. 那么您的代码将如下所示。

        无效排序(列出团队) { 而(!验证器。有效(团队)) { 收藏品。洗牌(团队); } }

      【讨论】:

        猜你喜欢
        • 2011-06-03
        • 1970-01-01
        • 2010-10-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-10-06
        • 1970-01-01
        • 2019-10-10
        相关资源
        最近更新 更多