问题 B: 循环比赛日程表

题目描述

设有N个选手进行循环比赛,其中N=2^m,要求每名选手要与其他N−1名选手都赛一次,每名选手每天比赛一次,循环赛共进行N−1天,要求每天没有选手轮空。

输入

输入:M。

输出

输出:表格形式的比赛安排表。一行各数据间用一个空格隔开。

样例输入

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;
const int Maxn=33, Maxm=5;
int matchlist[Maxn][Maxn];
int m;
int main()
{
    cin>>m;
    int n=1<<m; // qiu 2^m
    int k=1, half=1;
    matchlist[0][0]=1;
    while (k<=m)
    {
        for (int i=0;i<half;i++)
            for (int j=0;j<half; j++)
        {
            matchlist[i][j+half]=matchlist[i][j]+half;
        }
        for (int i=0;i<half;i++)
            for (int j=0;j<half;j++)
        {
            matchlist[i+half][j]=matchlist[i][j+half];
            matchlist[i+half][j+half]=matchlist[i][j];
        }
        half*=2;
        k++;
    }
    for (int i=0;i<n;i++)
    {
        for (int j=0;j<n;j++)
            cout<<matchlist[i][j]<<" ";
        cout<<endl;
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值