一种方法如下:
给团队编号 1..n。(本例中 n=8)将所有团队写成两行。
列显示哪些球队将参加该轮比赛(1 对 8、2 对 7,...)。
1 2 3 4
8 7 6 5
现在,保持 1 固定,但旋转(顺时针)所有其他团队。在第 2 周,您将获得
1 8 2 3
7 6 5 4
在第 3 周,你得到
1 7 8 2
6 5 4 3
这将持续到第 n-1 周,在这种情况下,
1 3 4 5
2 8 7 6
如果 n 是奇数,做同样的事情,但添加一个虚拟团队。与假球队比赛的人在那周得到再见。
例如:
1 2 3 4 5
9 8 7 6 0 (0 being the bye)
如上继续旋转。
代码示例:
void ListMatches(List<string> ListTeam)
{
if (ListTeam.Count % 2 != 0)
{
ListTeam.Add("Bye"); // If odd number of teams add a dummy
}
int numDays = (numTeams - 1); // Days needed to complete tournament
int halfSize = numTeams / 2;
List<string> teams = new List<string>();
teams.AddRange(ListTeam); // Add teams to List and remove the first team
teams.RemoveAt=(0);
int teamsSize = teams.Count;
for (int day = 0; day < numDays; day++)
{
Console.WriteLine("Day {0}", (day + 1));
int teamIdx = day % teamsSize;
Console.WriteLine("{0} vs {1}", teams[teamIdx], ListTeam[0]);
for (int idx = 1; idx < halfSize; idx++)
{
int firstTeam = (day + idx) % teamsSize;
int secondTeam = (day + teamsSize - idx) % teamsSize;
Console.WriteLine("{0} vs {1}", teams[firstTeam], teams[secondTeam]);
}
}
}
基本上,这样做是将除第一个团队之外的所有团队放入列表中。接下来,每天将您开始的索引增加 1。对于您关注的这个团队,您将这个团队与 Team1 匹配。对于列表中的下一个团队,您从列表的另一端开始将其匹配到相同的索引,但在它是 + 1 的任何一天处理第一个索引点。