-
总时间限制:
- 1000ms 内存限制:
- 65535kB
-
描述
-
设有n个选手进行循环比赛,其中n=2 m,要求每名选手要与其他n-1名选手都赛一次,每名选手每天比赛一次,循环赛共进行n-1天,要求每天没有选手轮空。
输入
- m(m<=10) 输出
- 表格形式的比赛安排表(数字之间以一个空格分开) 样例输入
-
3
样例输出
-
1 2 3 4 5 6 7 8 2 1 4 3 6 5 8 7 3 4 1 2 7 8 5 6 4 3 2 1 8 7 6 5 5 6 7 8 1 2 3 4 6 5 8 7 2 1 4 3 7 8 5 6 3 4 1 2 8 7 6 5 4 3 2 1
以下为个人意见及解答过程,如有不周到,还请谅解:
#include<iostream>
#include<cmath>
using namespace std;
int a[1029][1029];
void f(int k,int n)
{
if(n==2)
{
a[k][1]=k;
a[k][2]=k+1;
a[k+1][1]=k+1;
a[k+1][2]=k;
}
else
{
f(k,n/2);
f(k+n/2,n/2);
for(int i=k;i<k+n/2;i++)
for(int j=n/2+1;j<=n;j++)
a[i][j]=a[i+n/2][j-n/2];
for(int i=k+n/2;i<k+n;i++)
for(int j=n/2+1;j<=n;j++)
a[i][j]=a[i-n/2][j-n/2];
}
}
int main()
{
int n,m;
cin>>m;
n=pow(2,m);
f(1,n);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
cout<<a[i][j]<<' ';
cout<<endl;
}
return 0;
}
谢谢!