2017-03-14 78 views
-1

我們有一個16人聯賽和一個15周的循環賽時間表。每個球員互相比賽(循環賽)一次。 我想看看每個成員是否可以和其他玩家一起玩三次。 我跑過的每一輪知更鳥程序都會結束,一些玩家彼此玩5次,其他玩家只玩一次。 有沒有辦法讓這個工作,所以在循環賽格式中,所有球員都在同樣的四人組中進行三次比賽。 謝謝管理循環賽時間表

回答

-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; 
} 
+0

對不起,我不是一個程序員/數學家......我只是偶然發現網站尋找我的高爾夫聯賽時間表問題的答案。 如果你不是在這裏提供問題的答案,我明白。 –

+0

這是編程問題的網站,所以我給了你一個編程答案。我不確定你還想要什麼。 – jmbockhorst

+0

我想也許你可以給我的時間表,我正在尋找。別擔心... –

-1

我想你可能正在尋找惠斯特的設計。 Go here然後點擊'Whist'和'16 items'。桌子變成四人組,雙人組是你的循環賽的遊戲。下面重複相同的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)]