原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=1342

部分题目:

  In a Lotto I have ever played, one has to select 6 numbers from the set {1,2,…,49}. A popular strategy to play Lotto – although it doesn't increase your chance of winning – is to select a subset S containing k (k>6) of these 49 numbers, and then play several games with choosing numbers only from S. For example, for k=8 and S = {1,2,3,5,8,13,21,34} there are 28 possible games: [1,2,3,5,8,13], [1,2,3,5,8,21], [1,2,3,5,8,34], [1,2,3,5,13,21], … [3,5,8,13,21,34].

分析:

  相信很多同学看到这题一位很简单,其实真的挺简单的。。。首先我们先找出输出的规律不难发现他的规律,找到规律就不难写代码了。

源码:

 1 #include<stdio.h>
 2 int main()
 3 {
 4     int a[6],b[14],n,i;
 5     while(scanf("%d",&n),n)
 6     {
 7         for(i=0;i<n;i++)
 8             scanf("%d",&b[i]);
 9         for(a[0]=0;a[0]<n-5;a[0]++)
10             for(a[1]=a[0]+1;a[1]<n-4;a[1]++)
11                 for(a[2]=a[1]+1;a[2]<n-3;a[2]++)
12                     for(a[3]=a[2]+1;a[3]<n-2;a[3]++)
13                         for(a[4]=a[3]+1;a[4]<n-1;a[4]++)
14                             for(a[5]=a[4]+1;a[5]<n;a[5]++)
15                                 printf("%d %d %d %d %d %d\n",b[a[0]],b[a[1]],b[a[2]],b[a[3]],b[a[4]],b[a[5]]);
16         printf("\n");
17     }
18     return 0;
19 }

 

转载于:https://www.cnblogs.com/loveonepeople/p/3655068.html