1325:【例7.4】 循环比赛日程表
时间限制: 1000 ms 内存限制: 65536 KB
提交数: 6890 通过数: 3916
【题目描述】
设有NN个选手进行循环比赛,其中N=2M2M,要求每名选手要与其他N−1N−1名选手都赛一次,每名选手每天比赛一次,循环赛共进行N−1N−1天,要求每天没有选手轮空。
【输入】
输入:MM。
【输出】
输出:表格形式的比赛安排表。一行各数据间用一个空格隔开。
【输入样例】
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<bits/stdc++.h>
using namespace std;
int a[1025][1025];
int main()
{
int m;
int k=1,half=1;
cin>>m;
int n=1<<m;
a[0][0]=1;
while(k<=m)
{
for(int i=0;i<half;i++)
for(int j=0;j<half;j++)
a[i][j+half]=a[i][j]+half;
for(int i=0;i<half;i++)
for(int j=0;j<half;j++)
{
a[i+half][j]=a[i][j+half];
a[i+half][j+half]=a[i][j];
}
half*=2;
k++;
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
printf("%d ",a[i][j]);
cout<<endl;
}
return 0;
}