高手请进来,挑战一下!

来源:百度知道 编辑:UC知道 时间:2024/09/21 13:35:30
32个队员参加乒乓球比赛,其中有4名种子选手,且两名种子选手之间不能交手。编写 程序输出所有的比赛分组方式
忘了说了,两个人分为一组
上面的题不回就算了,当然如果能回我非常高兴
重要是回答下3个题
1.int a[5]={1,2,3,4,5};
printf("%d\n",*((int*)(&a+1)-2));
输出为什么是4
2. 有1001个球。甲乙两人交替取球,每次可取1、2、4个球,谁拿到最后一个球就算输。如果甲先拿,问他有没有必胜的把握?为什么?
3.有红、绿、蓝三色球分别3,2,1个。取任意两个不同颜色的球都会使它们变成第三种颜色的两个球。问最少取多少次,可使这些球都变成同一种颜色?

#include <stdio.h>

unsigned long g_num = 0;

typedef struct player_t
{
int idx;
unsigned char type;
} player_t;

/*n must be even*/
void func(player_t a[], int n, int t)
{
int i;
player_t x;

if (t == n - 2) {
for (i = 0; i < n -1; i += 2) {
printf("[%d %d] ", a[i].idx, a[i+1].idx);
}
printf("\n");
g_num++;
return;
}

for (i = t + 1; i < n; i++) {
if (a[i].type + a[t].type == 2) continue;
x = a[t + 1]; a[t + 1] = a[i]; a[i] = x;
func(a, n, t + 2);
x = a[t + 1]; a[t + 1] = a[i]; a[i] = x;
}
}

#define N 32
#define M 4

int main()
{
player_t a[N];
int i;

if (N % 2 != 0) return -1;

for (i = 0; i < N; i++