我们有16人联赛和15周的循环赛程。每个玩家互相对战(循环赛)一次。 我想看看每个成员是否可以与另一个玩家完全相同的四人玩3次。 我运行的每个循环赛程都会结束,有些玩家互相玩5次,其他玩家只玩过一次。 有没有办法让这个工作,所以在循环格式内,所有玩家在同一个四人游戏正好3次。 感谢
答案 0 :(得分:-1)
这是我如何在C ++中解决这个问题。这是一个简单的程序,可以让团队随机进入联赛,然后生成一个随机计划,每个团队可以在其他三个团队中进行偶数次。您可以根据需要进一步自定义它。
#include <vector>
#include <string>
std::vector<std::string> createSchedule(std::vector<std::string> teams, int numberOfGames)
{
//Create the randomized schedule
std::vector<std::string> schedule;
int counter = 0;
for (int i = 0; i < numberOfGames; i++) {
std::string game1;
std::string game2;
if (counter == 0) {
game1 = teams[0] + " vs " + teams[1];
game2 = teams[2] + " vs " + teams[3];
}
else if (counter == 1) {
game1 = teams[0] + " vs " + teams[2];
game2 = teams[1] + " vs " + teams[3];
}
else if (counter == 2) {
game1 = teams[0] + " vs " + teams[3];
game2 = teams[1] + " vs " + teams[2];
}
schedule.push_back(game1);
schedule.push_back(game2);
if (counter == 2) {
counter = 0;
}
else {
counter++;
}
}
return schedule;
}
int main()
{
std::vector<std::string> teams = { "Team1", "Team 2", "Team 3", "Team 4", "Team 5", "Team 6", "Team 7", "Team 8", "Team 9", "Team 10", "Team 11", "Team 12", "Team 13", "Team 14", "Team 15", "Team 16" };
std::vector<std::string> group1;
std::vector<std::string> group2;
std::vector<std::string> group3;
std::vector<std::string> group4;
//randomize teams into groups
for (int i = 0; i < teams.size(); i++) {
int num = rand() % 15;
if (num >= 0 && num < 4 && group1.size() < 4) {
group1.push_back(teams[i]);
}
else if (num >= 4 && num < 8 && group2.size() < 4) {
group2.push_back(teams[i]);
}
else if (num >= 8 && num < 12 && group3.size() < 4) {
group3.push_back(teams[i]);
}
else if (num >= 12 && num < 16 && group4.size() < 4) {
group4.push_back(teams[i]);
}
else {
if (group1.size() < 4) {
group1.push_back(teams[i]);
}
else if (group2.size() < 4) {
group2.push_back(teams[i]);
}
else if (group3.size() < 4) {
group3.push_back(teams[i]);
}
else if (group4.size() < 4) {
group4.push_back(teams[i]);
}
}
}
//Create a schedule of 15 games for each group
std::vector<std::string> schedule1 = createSchedule(group1, 15);
std::vector<std::string> schedule2 = createSchedule(group2, 15);
std::vector<std::string> schedule3 = createSchedule(group3, 15);
std::vector<std::string> schedule4 = createSchedule(group4, 15);
//Combine them into one big master schedule group by each set of games
//The first 8 games would be the first week of games for the whole league, etc...
std::vector<std::string> masterSchedule;
for (int i = 0; i < schedule1.size(); i += 2) {
masterSchedule.push_back(schedule1[i]);
masterSchedule.push_back(schedule1[i + 1]);
masterSchedule.push_back(schedule2[i]);
masterSchedule.push_back(schedule2[i + 1]);
masterSchedule.push_back(schedule3[i]);
masterSchedule.push_back(schedule3[i + 1]);
masterSchedule.push_back(schedule4[i]);
masterSchedule.push_back(schedule4[i + 1]);
}
return 0;
}
答案 1 :(得分:-1)
我想你可能正在寻找一个Whist设计。 Go here点击“Whist”和“16项”。桌子变成了四人组,对是你的循环赛。下面重复相同的15轮计划。
[(16 1) ( 9 14)] [( 2 4) ( 5 8)] [( 3 10) (12 13)] [( 6 15) ( 7 11)]
[(16 2) (10 15)] [( 3 5) ( 6 9)] [( 4 11) (13 14)] [( 7 1) ( 8 12)]
[(16 3) (11 1)] [( 4 6) ( 7 10)] [( 5 12) (14 15)] [( 8 2) ( 9 13)]
[(16 4) (12 2)] [( 5 7) ( 8 11)] [( 6 13) (15 1)] [( 9 3) (10 14)]
[(16 5) (13 3)] [( 6 8) ( 9 12)] [( 7 14) ( 1 2)] [(10 4) (11 15)]
[(16 6) (14 4)] [( 7 9) (10 13)] [( 8 15) ( 2 3)] [(11 5) (12 1)]
[(16 7) (15 5)] [( 8 10) (11 14)] [( 9 1) ( 3 4)] [(12 6) (13 2)]
[(16 8) ( 1 6)] [( 9 11) (12 15)] [(10 2) ( 4 5)] [(13 7) (14 3)]
[(16 9) ( 2 7)] [(10 12) (13 1)] [(11 3) ( 5 6)] [(14 8) (15 4)]
[(16 10) ( 3 8)] [(11 13) (14 2)] [(12 4) ( 6 7)] [(15 9) ( 1 5)]
[(16 11) ( 4 9)] [(12 14) (15 3)] [(13 5) ( 7 8)] [( 1 10) ( 2 6)]
[(16 12) ( 5 10)] [(13 15) ( 1 4)] [(14 6) ( 8 9)] [( 2 11) ( 3 7)]
[(16 13) ( 6 11)] [(14 1) ( 2 5)] [(15 7) ( 9 10)] [( 3 12) ( 4 8)]
[(16 14) ( 7 12)] [(15 2) ( 3 6)] [( 1 8) (10 11)] [( 4 13) ( 5 9)]
[(16 15) ( 8 13)] [( 1 3) ( 4 7)] [( 2 9) (11 12)] [( 5 14) ( 6 10)]