循环比赛日程表

w 【问题描述】
w    设有N个选手进行循环比赛,其中N=2M,要求每名选手要与其他N-1名选手都赛一次,每名选手每天比赛一次,循环赛共进行N-1天,要求每天没有选手轮空。
w    输入:M
w    输出:表格形式的比赛安排表
w 【样例输入】 match.in
w    3
w 【样例输出】 match.out
w     1  2  3  4  5  6  7  8
w    2  1  4  3  6  5  8  7
w    3  4  1  2  7  8  5  6
w    4  3  2  1  8  7  6  5
w    5  6  7  8  1  2  3  4
w    6  5  8  7  2  1  4  3
w    7  8  5  6  3  4  1  2
w    8  7  6  5  4  3  2  1
 1 #include<cstdio>
 2 const int MAXN=33,MAXM=5;
 3 int matchlist[MAXN][MAXN];
 4 int m;
 5 int main()
 6 {
 7     printf("Input m:");
 8     scanf("%d",&m);
 9     int n=1<<m,k=1,half=1;                              // 1<<m 相当于 2^m
10     matchlist[0][0]=1;
11     while (k<=m)
12     {
13         for (int i=0;i<half;i++)                           //构造右上方方阵
14             for (int j=0;j<half;j++)
15                 matchlist[i][j+half]=matchlist[i][j]+half;
16         for (int i=0;i<half;i++)                           //对称交换构造下半部分方阵
17             for (int j=0;j<half;j++)
18             {
19                 matchlist[i+half][j]=matchlist[i][j+half];    //左下方方阵等于右上方方阵
20                 matchlist[i+half][j+half]=matchlist[i][j];    //右下方方阵等于左上方方阵
21             }
22         half*=2;
23         k++;
24     }
25     for (int i=0;i<n;i++)
26     {
27         for (int j=0;j<n;j++)
28             printf("%4d",matchlist[i][j]);
29         putchar('\n');
30     }
31     return 0;
32 }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值