/*
运动会
问题:某个项目的n个选手进行循环比赛,其中n = 2m次幂,要求每名选手要与其他n-1名选手都赛一次。每名选手每天比赛一次,循环赛共进行-1天,要求每天没有选手轮空。
输入
2
输出
1 2 3 4
2 1 4 3
3 4 1 2
4 3 2 1
*/
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<iomanip>
#include<cstring>
#include<algorithm>
using namespace std ;
const int maxn = 520 ;
int ans[maxn][maxn] ;
int main()
{
int m ;
while(scanf("%d" , &m) != EOF)
{
int n = 1 << m ;
int t = 1 ;
ans[0][0] = 1 ;
do
{
for(int i = 0 ; i < t ; i++)
{
for(int j = 0 ; j < t ; j++)
{
ans[i][j + t] = ans[i][j] + t ;
ans[i + t][j] = ans[i][j + t] ;
ans[i + t][j + t] = ans[i][j] ;
}
}
t <<= 1 ;
}while(t != n) ;
for(int i = 0 ; i < n ; i++)
{
for(int j = 0 ; j < n ; j++)
{
cout<< setw(4) << ans[i][j] ;
}
cout<< endl ;
}
}
return 0 ;
}
运动会 循环图
最新推荐文章于 2021-05-22 10:58:16 发布