1.循环赛
#include<iostream>
using namespace std;
const int SIZE = 50;
int a[SIZE][SIZE];
void copy(int n);
void tournament(int n);
int odd(int n);
void makecopy(int n);
void copyodd(int n);
int main()
{
int n;
int i, j;
cout << "请输入队伍数:";
cin >> n;
tournament(n);
if (odd(n))
{
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n + 1; j++)
if (a[i][j] == n + 1)
cout << "0 ";
else
cout << a[i][j] << " ";
cout << endl;
}
}
else
{
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n; j++)
cout << a[i][j] << " ";
cout << endl;
}
}
}
void tournament(int n)
{
if (n == 1)
{
a[1][1] = 1;
return;
}
if (odd(n))
{
tournament(n + 1);
return;
}
tournament(n / 2);
makecopy(n);
}
int odd(int n)
{
if (n % 2 == 1)
return 1;
else return 0;
}
void makecopy(int n)
{
if (n / 2 > 1 && odd(n / 2))
copyodd(n);
else
copy(n);
}
void copy(int n)
{
int m = n / 2;
for (int i = 1; i <= m; i++)
for (int j = 1; j <= m; j++)
{
a[i][j + m] = a[i][j] + m;
a[i + m][j] = a[i][j + m];
a[i + m][j + m] = a[i][j];
}
}
void copyodd(int n)
{
int b[SIZE];
int m = n / 2;
for (int i = 1; i <= m; i++)
{
b[i] = m + i;
b[m + i] = b[i];
}
for (int i = 1; i <= m; i++)
{
for (int j = 1; j <= m + 1; j++)
{
if (a[i][j]