Cycle calendar problems, cycle calendar
There are n = 2 k contestants participating in the competition. A calendar meeting the following requirements must be designed:
(1) Each contestant must compete with other n-1 contestants once;
(2) Each contestant can only play once a day.
(3) Round Robin lasts for a total of N-1 days.
Design a competition calendar. The table has n rows and n-1 columns, and row I j columns are the contestants on the j day of the contestant.
# Include <stdio. h> # include <math. h> int a [100] [100]; void match (int k) {int n, temp, I, j; n = 2; // k = 0 two contestants can directly obtain a [1] [1] = 1; a [1] [2] = 2; a [2] [1] = 2; a [2] [2] = 1; for (I = 1; I <k; I ++) // iterative processing, process 2 ^ n .... 2 ^ k contestant's competition schedule {temp = n; n = n * 2; // fill in the lower left corner element for (I = temp + 1; I <= n; I ++) for (j = 1; j <= temp; j ++) a [I] [j] = a [I-temp] [j] + temp; // for (I = 1; I <= temp; I ++) // copy the elements in the lower left corner to the upper right corner for (j = temp + 1; j <= n; j ++) a [I] [j] = a [I + temp] [(j + Temp) % n]; for (I = temp + 1; I <= n; I ++) // copy the element in the upper left corner to the lower right corner for (j = temp + 1; j <= n; j ++) a [I] [j] = a [I-temp] [j-temp];} for (I = 1; I <= n; I ++) for (j = 1; j <= n; j ++) {printf ("% d ", a [I] [j]); if (j = n) printf ("\ n") ;}} int main () {int k; scanf ("% d", & k); if (k! = 0) match (k );}