我被赋予了为公司团队竞赛制定计划的任务。最初我认为这将是非常微不足道的,但我在提出有效的解决方案时遇到了一些麻烦。以下是需要满足的事实:
这不是循环赛,因为所有球队都不会互相比赛。它类似于Swiss Tournament,但是具有所有团队必须玩的多种游戏类型的约束。我正在努力找出正确的算法来确定这个时间表,任何帮助或信息都会很好。
答案 0 :(得分:2)
我认为你可以使用本地搜索,但让我给你一个数学结构。
将16支球队分为8支A队和8支B队。除了2支B队外,每支A队都将参加比赛。除了2支球队外,每支B队都将参加比赛。
这种结构需要两个相互正交的8x8拉丁方,例如,
abcdehfg
badchegf
cdabgfhe
dcbafgeh
ehgfabdc
hefgbacd
fghedcab
gfehcdba
abcdefgh
cdabhgfe
efhgabdc
hgefcdba
dcbaghef
badcfehg
feghbacd
ghfedcab
按A队对行进行索引,按B队对列进行索引。第一个拉丁方的条目指定A队与B队比赛的活动。其中两封信被视为休息。根据拉丁方的属性,每个团队只完成一次(并且休息两次)。
第二个拉丁方的条目表示A队与B队(或两队休息)的比赛时间。根据拉丁方的属性,每支球队在每一轮都做一件事。通过相互正交的拉丁方的属性,每个活动在每一轮中恰好发生一次。
在Python 3中:
import string
def latin8a(i, j):
return i ^ j
def latin8b(i, j):
b = i >> 2
return (i << 1) ^ (b << 3 | b << 1 | b) ^ j
a_teams = string.ascii_uppercase[:8]
b_teams = string.ascii_uppercase[8:16]
for i in range(8):
print()
print('Round', i + 1)
for j in range(6):
print(a_teams[latin8a(i, j)], 'vs', b_teams[latin8b(i, j)],
'in game type', string.ascii_lowercase[j])
输出:
Round 1
A vs I in game type a
B vs J in game type b
C vs K in game type c
D vs L in game type d
E vs M in game type e
F vs N in game type f
Round 2
B vs K in game type a
A vs L in game type b
D vs I in game type c
C vs J in game type d
F vs O in game type e
E vs P in game type f
Round 3
C vs M in game type a
D vs N in game type b
A vs O in game type c
B vs P in game type d
G vs I in game type e
H vs J in game type f
Round 4
D vs O in game type a
C vs P in game type b
B vs M in game type c
A vs N in game type d
H vs K in game type e
G vs L in game type f
Round 5
E vs L in game type a
F vs K in game type b
G vs J in game type c
H vs I in game type d
A vs P in game type e
B vs O in game type f
Round 6
F vs J in game type a
E vs I in game type b
H vs L in game type c
G vs K in game type d
B vs N in game type e
A vs M in game type f
Round 7
G vs P in game type a
H vs O in game type b
E vs N in game type c
F vs M in game type d
C vs L in game type e
D vs K in game type f
Round 8
H vs N in game type a
G vs M in game type b
F vs P in game type c
E vs O in game type d
D vs J in game type e
C vs I in game type f