问题 E: 循环比赛日程表
时间限制: 1 Sec 内存限制: 128 MB题目描述
设有N个选手进行循环比赛,其中N=2M,要求每名选手要与其他N-1名选手都赛一次,每名选手每天比赛一次,循环赛共进行N-1天,要求每天没有选手轮空。
输入
输入:M
输出
w输出:表格形式的比赛安排表(右对齐输出,占3位)
样例输入
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<cstdio>
#include<cstring>
#include<cmath>
#include<iomanip>
#include<cstdlib>
using namespace std;
int a[1000][1000],n,m;
int main()
{
// freopen("in.txt","r",stdin);
cin>>m;
n=1;
for(int i=1;i<=m;i++)
n*=2;
//system("pause");
//mem(1,n);
int s=1;
for(int i=1;i<=m;i++)
{
// system("pause");
for(int j=1;j<=s;j++)
for(int h=1;h<=s;h++)
{
a[j][h+s]=a[j][h]+s;
// cout<<a[j][h+s];
}
// system("pause");
for(int j=1;j<=s;j++)
for(int h=1;h<=s;h++)
{
a[j+s][h]=a[j][h+s];
a[j+s][h+s]=a[j][h];
}
s*=2;
// system("pause");
}
for(int i=1;i<=n;i++)
{ for(int j=1;j<=n;j++)
{
printf("%3d",a[i][j]+1);
}
cout<<endl;
}//mem()
//cout<<o;
//while(1);
return 0;
}