| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 706 人关注过本帖
标题:一个数学问题,想编程运算程序,拜请各位高手帮忙!
只看楼主 加入收藏
xxxbook1234
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2013-6-3
结帖率:0
收藏
已结贴  问题点数:20 回复次数:7 
一个数学问题,想编程运算程序,拜请各位高手帮忙!
小妹初学编程,有个数列组合的问题我实在不会,拜请各位前辈帮我编个小程序,程序是这样要求的:
   
    输入a1,a2,a3,a4,a5,a6,a7这七个数列(其中可能有空数列),数列中的数均为自然数,而且都不重复,然后分别从数列a1,a2,a3,a4,a5,a6,a7中随即取出n1,n2,n3,n4,n5,n6,n7个数组成新数列,其中要求:3≥n1,n2,n3,n4,n5,n6≥0,1≥n7≥0,并且,n1+n2+n3+n4+n5+n6+n7=6(即最后输出的数列均为六个数字),且n1,n2,n3,n4,n5,n6中至少一个,至多四个为零。请输出所有组合成的新数列。(数列中数字之间以空格隔开)
  

    谢谢大家!
搜索更多相关主题的帖子: 自然数 而且 
2013-06-03 16:04
xxxbook1234
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2013-6-3
收藏
得分:0 
难道就没有高手能帮助我一下,高手在哪里???
2013-06-04 00:00
小飞蛋
Rank: 2
来 自:江西财经大学
等 级:论坛游民
帖 子:9
专家分:20
注 册:2012-12-21
收藏
得分:7 
这个条件有点。。。。

追求C的言语。希望可以用TA来解释我的世界。
2013-06-04 12:50
xxxbook1234
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2013-6-3
收藏
得分:0 
回复 3楼 小飞蛋
这个能编吗?
2013-06-04 22:02
蚕头燕尾
Rank: 10Rank: 10Rank: 10
来 自:Gryffindo
等 级:贵宾
威 望:12
帖 子:734
专家分:1546
注 册:2013-3-24
收藏
得分:7 
不是大家不想帮楼主,只是这种程序实在写起来不爽。
而且,我自己就不懂3≥n1,n2,n3,n4,n5,n6≥0到底是想说什么意思?
随即取出n1,n2,n3,n4,n5,n6,n7个数组成新数列。。。。这里我首先想到的是循环嵌套(在不考虑运行效率的情况下)

楼主这样的问题其实最好应该具体只问其中的一个小的方面,毕竟大部分的部分还是应该能写的八九不离十的是不是?

或者只问大概思路也行~

学习编程,为的是表达自己的思想,而不是被别人的思想所禁锢。要先明白自己想干嘛,而不要先问别人让你干嘛。               

                                                                                                                    Black Cat      Hello Tomorrow~
2013-06-04 23:58
xxxbook1234
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2013-6-3
收藏
得分:0 
回复 5楼 蚕头燕尾
3≥n1,n2,n3,n4,n5,n6≥0,这个意思很明确,n是从数列里取出数的个数,介于0到3之间,说穿了就是可能取1个,可能取2个,也可能取3个,也可能一个都不取
2013-06-05 01:51
菜鸟一支
Rank: 6Rank: 6
来 自:何美杭
等 级:侠之大者
威 望:1
帖 子:121
专家分:456
注 册:2012-10-10
收藏
得分:0 
初学编程就搞这么复杂的问题啊,我个人觉得这个问题挺复杂的,献丑一下了,坐等高手(我写的这个代码很耗时)。PS:刚看到你说没高手,其实论坛上高手很多
#include <stdio.h>
#include<math.h>
void main()
{    int i=0,j=0,k=0,l=0,m=0,n=0,o=0,a,a1,a2,a3,b,b1,b2,b3,c,c1,c2,c3,d,d1,d2,d3,e,e1,e2,e3,f,f1,f2,f3,g,g1,g2,g3,n1,n2,n3,n4,n5,n6,n7,flag,z;
    int aaa[50],bbb[50],ccc[50],ddd[50],eee[50],fff[50],ggg[50];
    int p,q,r,s,t,u,v;
    char cc,a11[100],a22[100],a33[100],a44[100],a55[100],a66[100],a77[100];
    cc=getchar();
    while(cc!='\n')
        {    if(cc!=' ')
                {a11[i]=cc;i++;}
            cc=getchar();
        }
        cc=getchar();
    while(cc!='\n')
        {    if(cc!=' ')
                {a22[j]=cc;j++;}
            cc=getchar();
        }
        cc=getchar();
    while(cc!='\n')
        {    if(cc!=' ')
                {a33[k]=cc;k++;}
            cc=getchar();
        }
        cc=getchar();
    while(cc!='\n')
        {    if(cc!=' ')
                {a44[l]=cc;l++;}
            cc=getchar();
        }
        cc=getchar();
    while(cc!='\n')
        {    if(cc!=' ')
                {a55[m]=cc;m++;}
            cc=getchar();
        }
        cc=getchar();
    while(cc!='\n')
        {    if(cc!=' ')
                {a66[n]=cc;n++;}
            cc=getchar();
        }
        cc=getchar();
    while(cc!='\n')
        {    if(cc!=' ')
                {a77[o]=cc;o++;}
            cc=getchar();
        }                                //数列的输入完毕
    for(n1=0;n1<=3;n1++)
    for(n2=0;n2<=3;n2++)
    for(n3=0;n3<=3;n3++)        
    for(n4=0;n4<=3;n4++)
    for(n5=0;n5<=3;n5++)
    for(n6=0;n6<=3;n6++)
    for(n7=0;n7<=1;n7++)
        if((n1+n2+n3+n4+n5+n6+n7)==6)
            {    flag=0;            
                if(n1==0)
                    flag++;
                if(n2==0)
                    flag++;
                if(n3==0)
                    flag++;
                if(n4==0)
                    flag++;
                if(n5==0)
                    flag++;
                if(n6==0)
                    flag++;
                if(flag>0&&flag<=4)
                {    if(n1<=i&&n2<=j&&n3<=k&&n4<=l&&n5<=m&&n6<=n&&n7<=o)
                    for(a=0;a<=(pow(2,i)-1);a++)
                    for(b=0;b<=(pow(2,j)-1);b++)
                    for(c=0;c<=(pow(2,k)-1);c++)
                    for(d=0;d<=(pow(2,l)-1);d++)
                    for(e=0;e<=(pow(2,m)-1);e++)
                    for(f=0;f<=(pow(2,n)-1);f++)
                    for(g=0;g<=(pow(2,o)-1);g++)
                        {    a3=0;b3=0;c3=0;d3=0;e3=0;f3=0;g3=0;
                            p=0;q=0;r=0;s=0;t=0;u=0;v=0;
                            a1=a%2;a2=a/2;
                            aaa[p]=a1;
                            p++;
                            if(a1==1)
                                a3++;
                                while(a2!=0)
                                    {a1=a2%2;a2=a2/2;aaa[p]=a1;p++;
                                        if(a1==1)
                                        a3++;
                                    }
                            b1=b%2;b2=b/2;
                            bbb[q]=b1;
                            q++;
                            if(b1==1)
                                b3++;
                                while(b2!=0)
                                    {b1=b2%2;b2=b2/2;bbb[q]=b1;q++;
                                        if(b1==1)
                                        b3++;
                                    }
                            c1=c%2;c2=c/2;
                            ccc[r]=c1;
                            r++;
                            if(c1==1)
                                c3++;
                                while(c2!=0)
                                    {c1=c2%2;c2=c2/2;ccc[r]=c1;r++;
                                        if(c1==1)
                                        c3++;
                                    }
                            d1=d%2;d2=d/2;
                            ddd[s]=d1;
                            s++;
                            if(d1==1)
                                d3++;
                                while(d2!=0)
                                    {d1=d2%2;d2=d2/2;ddd[s]=d1;s++;
                                        if(d1==1)
                                        d3++;
                                    }
                            e1=e%2;e2=e/2;
                            eee[t]=e1;
                            t++;
                            if(e1==1)
                                e3++;
                                while(e2!=0)
                                    {e1=e2%2;e2=e2/2;eee[t]=e1;t++;
                                        if(e1==1)
                                        e3++;
                                    }
                            f1=f%2;f2=f/2;
                            fff[u]=f1;
                            u++;
                            if(f1==1)
                                f3++;
                                while(f2!=0)
                                    {f1=f2%2;f2=f2/2;fff[u]=f1;u++;
                                        if(f1==1)
                                        f3++;
                                    }
                            g1=g%2;g2=g/2;
                            ggg[v]=g1;
                            v++;
                            if(g1==1)
                                g3++;
                                while(g2!=0)
                                    {g1=g2%2;g2=g2/2;ggg[v]=g1;v++;
                                        if(g1==1)
                                        g3++;
                                    }
                        if(a3==n1&&b3==n2&&c3==n3&&d3==n4&&e3==n5&&f3==n6&&g3==n7)
                            {    for(z=0;z<=50;z++)
                                    if(aaa[z]==1)
                                    {printf("%c ",a11[z]);aaa[z]=0;}
                                for(z=0;z<=50;z++)
                                    if(bbb[z]==1)
                                    {printf("%c ",a22[z]);bbb[z]=0;}
                                for(z=0;z<=50;z++)
                                    if(ccc[z]==1)
                                    {printf("%c ",a33[z]);ccc[z]=0;}
                                for(z=0;z<=50;z++)
                                    if(ddd[z]==1)
                                    {printf("%c ",a44[z]);ddd[z]=0;}
                                for(z=0;z<=50;z++)
                                    if(eee[z]==1)
                                    {printf("%c ",a55[z]);eee[z]=0;}
                                for(z=0;z<=50;z++)
                                    if(fff[z]==1)
                                    {printf("%c ",a66[z]);fff[z]=0;}
                                for(z=0;z<=50;z++)
                                    if(ggg[z]==1)
                                    {printf("%c ",a77[z]);ggg[z]=0;}
                                printf("\n");
                            }
                           
                        }
                }

            }
}

[ 本帖最后由 菜鸟一支 于 2013-6-5 14:57 编辑 ]

小弟何美杭,所发表的都仅代表个人观点,欢迎批评指正。
2013-06-05 13:28
菜鸟一支
Rank: 6Rank: 6
来 自:何美杭
等 级:侠之大者
威 望:1
帖 子:121
专家分:456
注 册:2012-10-10
收藏
得分:7 
测试样例
输入(PS:输入七个数列):
1
2
3
4
5
6
7
输出
2 3 4 5 6 7
1 3 4 5 6 7
1 2 4 5 6 7
1 2 3 5 6 7
1 2 3 4 6 7
1 2 3 4 5 7

小弟何美杭,所发表的都仅代表个人观点,欢迎批评指正。
2013-06-05 13:35
快速回复:一个数学问题,想编程运算程序,拜请各位高手帮忙!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.031870 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved