1

我正在尝试用 PHP 编写一段代码,它将为每个团队制定循环赛类型锦标赛的最佳和最差结果。

此代码将在每轮比赛后执行,因此将查找每支球队的当前 WLT 记录以及每支球队未来的比赛时间表(所有这些信息都已存储在数据库中)。

我最初的想法是遍历每支球队的排名排列,并记住每支球队表现的极限。然而,经过进一步思考,我意识到对于这种情况下的 12 个团队,这将导致超过 4.79 亿个排列(这可能需要一点时间来计算,更不用说简洁的代码了)。

不幸的是,我担心我在设计一个逻辑系统来处理这个问题时已经达到了我的想象力的极限,所以任何人都可以提供的任何帮助都会很棒。

提前干杯爱德华

4

1 回答 1

0

我假设输了 0 分,平局 1 分,赢了 2 分。

For each team t
    Sort the teams by their current point table so the last place
    team(s) come first and the top teams come last. Put all teams tied with t before t.
    Let i be the position of team t in this list
    From here on I'll name teams by their position in the list. So we have
    from left to right, teams currently worse than i, teams tied with team i, team i,
    and finally teams better than i.
    Make a working copy  of your matrix. For the rest of this
         iteration I'll implicitly refer to the working copy.
    Suppose (in the working copy) that team i has loses all its remaining games.
    For j from 0 up to i
         Make a backup copy of the working copy. 
         for( k:=n-1 ; k < j and j is behind or tied with i ; k := k-1 )
             If k hasn't played j and j is behind i
                 suppose that j beats k
             Else if k hasn't played j /* and is tied with k */
                  suppose that j ties k
          if j is still behind i
             revert to the backup made before the preceding loop
          discard the backup copy
          for all games j has yet to play suppose j loses

     At this point, all remaining games in the working copy are between teams ahead
     of team i, assume all remaining games are ties.
     Now (if we have really constructed a worst case scenario) the rank of team i
     in the working copy is the worst it can do. I.e. team i beats "count

我不完全确定这给出了确切的下限。上限是对称的。

于 2013-11-06T20:22:36.603 回答