- 论坛徽章:
- 0
|
赛程安排的算法
to narkissos:
我把你的结果贴在下面了(我把你的n改成6)
- sh-2.05b$ ./c5
- 1-2, 3-4, 5-6,
- 1-3, 2-4,
- 1-4, 2-3,
- 1-5, 2-6,
- 1-6, 2-5,
- 3-5, 4-6,
- 3-6, 4-5,
复制代码
下面是我今天上午的结果和实现代码
- sh-2.05b$ ./c3 6
- A ->; B,C ->; D,E ->; F,
- A ->; C,B ->; D,F ->; E,
- A ->; D,B ->; E,C ->; F,
- A ->; E,B ->; F,D ->; C,
- A ->; F,B ->; C,D ->; E,
- B ->; A,C ->; E,D ->; F,
- C ->; A,D ->; B,
- C ->; B,D ->; A,
- E ->; A,F ->; B,
- E ->; B,F ->; A,
复制代码
- include <stdio.h>;
- #include <stdlib.h>;
- #define SIZE 100
- void
- resume(char *per,int num)
- {
- int i;
- for(i =0; i < num; i++)
- per[i] = i + 'A';
- }
- int
- main(int argc,char **argv)
- {
- int num,i,j,k=0,n=1,m;
- char flag[SIZE][SIZE];
- char per[SIZE];
- num = atoi(argv[1]);
- for(i = 0; i < num ; i++)
- flag[i][i] = -1;
- resume(per,num);
- while(k < num*(num-1)/(num/2)) {
- for(i = 0; i<num ;i++) {
- if (per[i] != -1) {
- for(n>;i ? (j=n):(j=i),m=0; (per[i] != -1)&& (m<num); j==num-1 ? (j=0):(j++),m++)
- if(flag[i][j] != -1 && per[j] != -1) {
- printf("%c ->; %c,",per[i],per[j]); /*i,j are selected*/
- flag[i][j] = -1;
- per[i] = per[j] = -1;
- (j==num-1) ? (n=0):(n=j+1);
- break;
- }
- }
- }
- k++;
- n=1;
- resume(per,num);
- printf("\n");
- }
- }
复制代码
你对比看看吧 |
|