这样做的一种方法如下:
给团队编号1..n。 (本例中n = 8) 将所有团队写入两行。
该列显示哪支球队将在该回合中进行比赛(1 vs 8,2 vs 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]);
}
}
}
基本上这是什么做的是把所有的球队,除了列表中的第一个。接下来,每天增加你开始的索引。对于您关注的这个团队,您将此团队与Team1匹配。对于列表中的下一个团队,您将其与列表另一端的相同索引进行匹配,但在第一个索引点处为+1时处理第一个索引点。
我不认为顺时针是单词你正在寻找。顺时针用于描述旋转的方向(如时钟的双手移动)。你能提供一个例子吗? – thatidiotguy 2014-10-20 17:29:57
如果你从马特琼斯看下面的答案,我想你会理解我的意思。如果您想象一下可能是国际象棋比赛的真实场景,该算法更容易理解。你玩一只手,顺时针移动,玩另一只手,再次移动。我的问题是将此运动转换为代码。 – MehtabC 2014-10-20 17:33:19
所以你的问题是如何实现这个编程..你有什么试过吗? – 2014-10-20 17:34:08