|
10鱼币
本帖最后由 wow7jiao 于 2018-7-13 10:43 编辑
http://bbs.fishc.org/thread-79184-1-4.html 原帖地址
01.#include <stdio.h>
02.
03.#define MAX_NUM 64
04.
05.int schedule[MAX_NUM+1][MAX_NUM+1];
06.
07.int arrange(int begin, int num);
08.
09.int arrange(int begin, int num)
10.{
11. int i, j;
12.
13. if (num == 2)
14. {
15. schedule[begin][1] = begin;
16. schedule[begin][2] = begin + 1;
17. schedule[begin+1][1] = begin + 1;
18. schedule[begin+1][2] = begin;
19. return 0;
20. }
21.
22. arrange(begin, num/2); <----我输入8个队伍,这里begin=1,num/2=4
23. arrange(begin + num/2, num/2);<----这里是不是being=1+8/2=5,num/2=8/2=4
24.
25. for (i = begin + num/2; i < begin + num; i++)
26. {
27. for (j = num/2 + 1; j <= num; j++)
28. {
29. schedule[i][j] = schedule[i-num/2][j-num/2];
30. }
31. }
32.
33. for (i = begin; i < begin + num/2; i++)
34. {
35. for (j = num/2 + 1; j <= num; j++)
36. {
37. schedule[i][j] = schedule[i+num/2][j-num/2];
38. }
39. }
40.}
41.
42.int main(void)
43.{
44. int num, i, j;
45.
46. printf("请输入参赛的队伍数量:");
47. scanf("%d", &num);
48.
49. // 检查num是否2的N次方
50. // 注意,这里是&,不是&&
51. // &是按位与操作,1&1==1,0&1==0,0&0 == 0
52. if (num & num - 1)
53. {
54. printf("参数队伍的数量必须是2的N次方!\n");
55. return -1;
56. }
57.
58. arrange(1, num);
59.
60. printf("编 号");
61.
62. for (i = 1; i < num; i++)
63. {
64. printf("\t第%d天", i);
65. }
66.
67. putchar('\n');
68.
69. for (i = 1; i <= num; i++)
70. {
71. for (j = 1; j <= num; j++)
72. {
73. printf("%3d\t", schedule[i][j]);
74. }
75. putchar('\n');
76. }
77.
78. return 0;
79.}
|
|