设有N个选手进行循环比赛,其中N=2
M
,要求每名选手要与其他N−1名选手都赛一次,每名选手每天比赛一次,循环赛共进行N−1天,要求每天没有选手轮空。
输入格式:
输入:M(M<=7)。
输出格式:
输出:表格形式的比赛安排表。一行各数据间用一个空格隔开。
输入样例:
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
说明,第一行为:1 2 3 4 5 6 7 8,1表示本行都是1号选手和其他选手的比赛,如第2个数为2(其下标可以看成1)表示第一天1号和2号比赛,第5个数为5(其下标可以看成4),表示1号和5号在第4天比赛。
(20分)
作者
严华云
单位
湖州师范学院
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
#include<iostream>
#include<math.h>
using namespace std;
#define max 128
int a[max][max];
void copy(int fr,int fl,int tr,int tl,int len){
for(int i=0;i<len;i++){
for(int j=0;j<len;j++)
a[tr+i][tl+j]=a[fr+i][fl+j];
}
}
void team(int r,int l,int len){
if(len==1)
return;
len=len/2;
//左上
team(r,l,len);
//右上
team(r,l+len,len);
//左下
copy(r,l+len,r+len,l,len);
//右下
copy(r,l,r+len,l+len,len);
}
int main(){
int n;
cin>>n;
n=pow(2,n);
for(int i=0;i<n;i++){
a[0][i]=i+1;
a[i][0]=i+1;
}
team(0,0,n);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cout<<a[i][j]<<" ";
}
cout<<endl;
}
}