计算可能的比赛结果

时间:2013-11-06 18:26:34

标签: php database logic tournament

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

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

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

我担心,在设计一个逻辑系统来处理这个问题时,我的想象力很大,所以任何人都可以提供的任何帮助都会很棒。

提前干杯 爱德华

1 个答案:

答案 0 :(得分: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

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