|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
不是很看得懂能不能来个大佬给个注释帮助理解
#include <stdio.h>
#define MAX_NUM 64
int schedule[MAX_NUM+1][MAX_NUM+1];
int arrange(int begin, int num);
int arrange(int begin, int num)
{
int i, j;
if (num == 2)
{
schedule[begin][1] = begin;
schedule[begin][2] = begin + 1;
schedule[begin+1][1] = begin + 1;
schedule[begin+1][2] = begin;
return 0;
}
arrange(begin, num/2);
arrange(begin + num/2, num/2);
for (i = begin + num/2; i < begin + num; i++)
{
for (j = num/2 + 1; j <= num; j++)
{
schedule[i][j] = schedule[i-num/2][j-num/2];
}
}
for (i = begin; i < begin + num/2; i++)
{
for (j = num/2 + 1; j <= num; j++)
{
schedule[i][j] = schedule[i+num/2][j-num/2];
}
}
}
int main(void)
{
int num, i, j;
printf("请输入参赛的队伍数量:");
scanf("%d", &num);
// 检查num是否2的N次方
// 注意,这里是&,不是&&
// &是按位与操作,1&1==1,0&1==0,0&0 == 0
if (num & num - 1)
{
printf("参数队伍的数量必须是2的N次方!\n");
return -1;
}
arrange(1, num);
printf("编 号");
for (i = 1; i < num; i++)
{
printf("\t第%d天", i);
}
putchar('\n');
for (i = 1; i <= num; i++)
{
for (j = 1; j <= num; j++)
{
printf("%3d\t", schedule[i][j]);
}
putchar('\n');
}
return 0;
}
|
-
|