以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  想做一个比赛对阵表,有没有好的算法?  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=82122)

--  作者:sloyy
--  发布时间:2016/3/11 19:20:00
--  想做一个比赛对阵表,有没有好的算法?
条件如下:单循环比赛,有N个队,M个比赛场地,排出对阵表
比如 5 个队,2个场地:

图片点击可在新窗口打开查看此主题相关图片如下:搜狗截图20160311191921.png
图片点击可在新窗口打开查看


可能还要考虑每个队的休息情况,要求尽量均匀.

[此贴子已经被作者于2016/3/11 19:24:01编辑过]

--  作者:大红袍
--  发布时间:2016/3/14 15:46:00
--  

参考代码

 

Dim rs As Integer = 5
Dim cs As Integer = 2
Dim dic_r As new Dictionary(of String, Integer)
Dim dic_b As new Dictionary(of String, Boolean)
For i As Integer = 1 To rs
    dic_r.add(i, 0)
    For j As Integer = i+1 To rs
        dic_b.add(i & "," & j, False)
    Next
Next

Do While True
    Dim min As Integer = 999
    Dim dic_bx As new Dictionary(of String, Integer)
    Dim ls_bx As new List(Of String)
    Dim arykey() As String = Nothing
    For Each key As String In dic_b.keys
        If dic_b(key) = False Then
            Dim ary As String() = key.split(",")
            Dim s As Integer = dic_r(ary(0)) + dic_r(ary(1))
            If s <= min Then
                min = s
                arykey = ary
            End If
        End If
    Next
    If arykey Is Nothing Then
        Exit Do
    Else
        dic_r(arykey(0)) += 1 \'场次+1
        dic_r(arykey(1)) += 1
        dic_b(arykey(0) & "," & arykey(1)) = True \'把此场设置为比赛
        output.show(arykey(0) & "," & arykey(1) & "(" & dic_r(arykey(0)) & " : " & dic_r(arykey(1)) & ")")
    End If
Loop


--  作者:大红袍
--  发布时间:2016/3/14 15:48:00
--  
2楼的代码。如果要做成随机,可以先打乱原先的队伍的顺序;或者是,取得最小min以后,再循环有多少个同值的场次,随机选一个。
--  作者:sloyy
--  发布时间:2016/3/17 23:36:00
--  
学习中,还不是很懂....