问题:设有n=2^k个选手参加循环赛,要求设计一个满足以下要求比赛日程表:
1)每个选手必须与其它n-1个选手各赛一次;
2)每个选手一天只能赛一次。
1 //循环赛日程表 2 #include<iostream> 3 #include<cstdio> 4 #include<cstdlib> 5 using namespace std; 6 int a[100][100]; 7 8 void Copy(int tox,int toy,int fromx,int fromy,int r){ 9 for( int i = 0; i < r; i++ ) 10 for( int j = 0; j < r; j++ ){ 11 a[tox+i][toy+j] = a[fromx+i][fromy+j]; 12 } 13 } 14 15 void Table(int k){ 16 int n = 1<<k; 17 for( int i = 0; i < n; i++ ) 18 a[0][i] = i+1; 19 for( int r = 1; r < n; r = r<<1 ) 20 for( int i = 0; i < n; i = i+r*2 ){ 21 Copy(r,r+i,0,i,r); 22 Copy(r,i,0,r+i,r); 23 } 24 } 25 26 void Out(int n){ 27 for( int i = 0; i < n; i++ ){ 28 for( int j = 0; j < n; j++ ) 29 printf("%3d",a[i][j]); 30 cout<<endl; 31 } 32 cout<<endl; 33 } 34 35 int main(){ 36 int k; 37 while( scanf("%d", &k) != EOF ){ 38 int n = 1<<k; 39 Table(k); 40 Out(n); 41 } 42 return 0; 43 }