Problem Description
There are 2 n (n <= 6) teams playing single-cycle games, which are planned to be completed within 2 n – 1 day, and each team plays one game every day. Design a game schedule so that each team competes with different opponents within 2 n – 1 day.
Input format
The input file matchplan.in consists of one line, and enter the value of n.
Output format
The output file matchplan.out has a total of (2 n – 1) lines, and line i outputs the match schedule for day i.
The format is: <i> AB, CD, .... Where i is the number of days, A and B are the numbers of the two sides of the game, each row has a total of 2 n-1 matches.
The format is: <i> AB, CD, .... Where i is the number of days, A and B are the numbers of the two sides of the game, each row has a total of 2 n-1 matches.
Sample input
2
Sample output
<1>1-2,3-4
<2>1-3,2-4
<3>1-4,2-3
<2>1-3,2-4
<3>1-4,2-3
The description of the sample output is wrong. The comma should be a space. The correct output format of the evaluation data is as follows:
Will not do, refer to https://blog.csdn.net/qq_34845121/article/details/60957163
1 #include <bits / stdc ++. H> 2 using namespace std; 3 int a [ 70 ] [ 70 ]; // a [i] [j] records whether team i and team j have played 4 int v [ 70 ] ; // v [i] records whether team i has played 5 int main () { 6 int n; 7 cin >> n; 8 int len = 1 ; 9 for ( int i = 1 ; i <= n ; i ++ ) { 10 len * = 2; // len = Number of teams 2 ^ n 11 } 12 for ( int i = 0 ; i <len- 1 ; i ++) { // Number of game days 2 ^ n-1, which is the number of lines to be output 13 printf ( " <% d> " , i + 1 ); // Output days 14 memset (v, 0 , sizeof v); // Reset (every team on the new day has no match) 15 for ( int j = 0 ; j <len / 2 ; j ++) { // n games per day, that is, how many matches are output per line 16 for ( int k = 1 ; k <= len; k ++) { // Traverse all teams, find the first team to participate 17 if (v [k] == 1 ) { // If the team has already come over on that day , Skip 18 continue ; 19 } 20 int judge = 0 ; // judge whether the two teams of k and h have played 21 for ( int h = 1 ; h <= len; h ++) { // traverse all teams, Find the second team to play 22 if (k == h) { // I can't compare with myself 23 continue ; 24 } 25 if (v [h] == 1 ) { // If the team has come over on that day, skip 26 continue ; 27 } 28 if (a [k] [h] == 0 && a [h] [ k] == 0 ) { // h, whether k teams played together on that day 29 printf ( " % d-% d " , k, h); // Team k and team h played 30 v [h] = 1 ; // Mark team h to stop playing today 31 v [k] = 1 ; //Mark k team will not play today. 32 a [k] [h] = 1 ; // Mark h and k have played today 33 judge = 1 ; // Mark the end of the jth game, jump to the next 34 break ; 35 } 36 } 37 if (judge == 1 ) { // The end of the jth game, skip to the next 38 break ; 39 } 40 } 41 } 42 printf ( " \ n " ); 43 } 44 return 0; 45 }