Lotto

原题地址: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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值