woodangel 发表于 2012-9-20 22:19

简单的码农问题!!!!

比如,数组{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19}   
要找出那些数相加等于20,
注意可能是2个数也可能是多个数,不限制

my8dacart 发表于 2012-9-20 22:34

依然打老虎 发表于 2012-9-20 23:53

用个递归函数吧

今心 发表于 2012-9-20 23:55

大神居然来发帖来助?

牛clear 发表于 2012-9-20 23:57

拿20来拆,拆成2个数相加,拆成3个数相加,4,5 ... ...
这比上面的循环递归加方便多了。

今心 发表于 2012-9-20 23:58

my8dacart 发表于 2012-9-20 22:34 static/image/common/back.gif
按 不同的相加位数 遍历所有可能出现的数值,这活计算机干起来得心应手。

不用所有的数,

因为是有顺序的排列。就算没顺序的,也可以先按顺序排列。

19+1=20,那么1后面的数就不用相加了
19+1=20,那么18比19小,18+1肯定不会是20.所以18可以从1后面的一个数加起

多位的也类些

Pentium9 发表于 2012-9-21 00:01

大师居然会被这种问题难住?

waln 发表于 2012-9-21 00:05

大一下学期的学生都能搞定

hkkhhk 发表于 2012-9-21 00:07

20 = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1
20 = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 2
20 = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 3
20 = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 2 + 2
20 = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 4
20 = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 2 + 3
20 = 1 + 1 + 1 + 1 + 1 + 1 + 1 +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 6 + 6 + 6
20 = 2 + 6 + 12
20 = 2 + 7 + 11
20 = 2 + 8 + 10
20 = 2 + 9 + 9
20 = 2 + 18
20 = 3 + 3 + 3 + 3 + 3 + 5
20 = 3 + 3 + 3 + 3 + 4 + 4
20 = 3 + 3 + 3 + 3 + 8
20 = 3 + 3 + 3 + 4 + 7
20 = 3 + 3 + 3 + 5 + 6
20 = 3 + 3 + 3 + 11
20 = 3 + 3 + 4 + 4 + 6
20 = 3 + 3 + 4 + 5 + 5
20 = 3 + 3 + 4 + 10
20 = 3 + 3 + 5 + 9
20 = 3 + 3 + 6 + 8
20 = 3 + 3 + 7 + 7
20 = 3 + 3 + 14
20 = 3 + 4 + 4 + 4 + 5
20 = 3 + 4 + 4 + 9
20 = 3 + 4 + 5 + 8
20 = 3 + 4 + 6 + 7
20 = 3 + 4 + 13
20 = 3 + 5 + 5 + 7
20 = 3 + 5 + 6 + 6
20 = 3 + 5 + 12
20 = 3 + 6 + 11
20 = 3 + 7 + 10
20 = 3 + 8 + 9
20 = 3 + 17
20 = 4 + 4 + 4 + 4 + 4
20 = 4 + 4 + 4 + 8
20 = 4 + 4 + 5 + 7
20 = 4 + 4 + 6 + 6
20 = 4 + 4 + 12
20 = 4 + 5 + 5 + 6
20 = 4 + 5 + 11
20 = 4 + 6 + 10
20 = 4 + 7 + 9
20 = 4 + 8 + 8
20 = 4 + 16
20 = 5 + 5 + 5 + 5
20 = 5 + 5 + 10
20 = 5 + 6 + 9
20 = 5 + 7 + 8
20 = 5 + 15
20 = 6 + 6 + 8
20 = 6 + 7 + 7
20 = 6 + 14
20 = 7 + 13
20 = 8 + 12
20 = 9 + 11
20 = 10 + 10

BeRush 发表于 2012-9-21 00:09

不需要这种循环遍历吧,肯定有比较简单的算法,比楼上的效率高n倍的

hkkhhk 发表于 2012-9-21 00:11

20 = 1 + 2 + 3 + 4 + 10
20 = 1 + 2 + 3 + 5 + 9
20 = 1 + 2 + 3 + 6 + 8
20 = 1 + 2 + 3 + 14
20 = 1 + 2 + 4 + 5 + 8
20 = 1 + 2 + 4 + 6 + 7
20 = 1 + 2 + 4 + 13
20 = 1 + 2 + 5 + 12
20 = 1 + 2 + 6 + 11
20 = 1 + 2 + 7 + 10
20 = 1 + 2 + 8 + 9
20 = 1 + 2 + 17
20 = 1 + 3 + 4 + 5 + 7
20 = 1 + 3 + 4 + 12
20 = 1 + 3 + 5 + 11
20 = 1 + 3 + 6 + 10
20 = 1 + 3 + 7 + 9
20 = 1 + 3 + 16
20 = 1 + 4 + 5 + 10
20 = 1 + 4 + 6 + 9
20 = 1 + 4 + 7 + 8
20 = 1 + 4 + 15
20 = 1 + 5 + 6 + 8
20 = 1 + 5 + 14
20 = 1 + 6 + 13
20 = 1 + 7 + 12
20 = 1 + 8 + 11
20 = 1 + 9 + 10
20 = 1 + 19
20 = 2 + 3 + 4 + 5 + 6
20 = 2 + 3 + 4 + 11
20 = 2 + 3 + 5 + 10
20 = 2 + 3 + 6 + 9
20 = 2 + 3 + 7 + 8
20 = 2 + 3 + 15
20 = 2 + 4 + 5 + 9
20 = 2 + 4 + 6 + 8
20 = 2 + 4 + 14
20 = 2 + 5 + 6 + 7
20 = 2 + 5 + 13
20 = 2 + 6 + 12
20 = 2 + 7 + 11
20 = 2 + 8 + 10
20 = 2 + 18
20 = 3 + 4 + 5 + 8
20 = 3 + 4 + 6 + 7
20 = 3 + 4 + 13
20 = 3 + 5 + 12
20 = 3 + 6 + 11
20 = 3 + 7 + 10
20 = 3 + 8 + 9
20 = 3 + 17
20 = 4 + 5 + 11
20 = 4 + 6 + 10
20 = 4 + 7 + 9
20 = 4 + 16
20 = 5 + 6 + 9
20 = 5 + 7 + 8
20 = 5 + 15
20 = 6 + 14
20 = 7 + 13
20 = 8 + 12
20 = 9 + 11

hkkhhk 发表于 2012-9-21 00:14

9楼代码
#include <StdAfx.h>
#include <iostream>

using namespace std;

#define target 20
#define len 19
int num = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
int times = {0};
FILE * f;
void fun(int sum, int start)
{
        if(sum == target)
        {
                int i = 0;
                int b;
                for(; i < len; ++i)
                {
                        for(int j = 0; j < times; ++j)
                        {
                                b = i;
                                fprintf(f, "%d = %d", target, num);
                                times--;
                                goto st2;
                        }
                }
                st2:
                for(; i < len; ++i)
                {
                        for(int j = 0; j < times; ++j)
                                fprintf(f, " + %d", num);
                }
                times++;
                fprintf(f, "\r\n");
        }
        for(int i = start; i < len; ++i)
        {
                if(num + sum <= target)
                {
                        times++;
                        fun(sum + num, i);
                        times--;
                }
        }
}

void main(void)
{
        f = fopen("d:\\desktop\\bbb.txt", "wb");
        fun(0, 0);
        system("pause");
}
11楼代码
#include <StdAfx.h>
#include <iostream>

using namespace std;

int num[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
#define len 19
#define target 20

void fun(int sum, int start)
{
        if(sum == target)
        {
                int i = 0;
                for(; i < len; ++i)
                {
                        if(num < 0)
                        {
                                printf("%d = %d", target, -num);
                                break;
                        }
                }
                for(; i < len; ++i)
                {
                        if(num < 0)
                        {
                                printf(" + %d", -num);
                        }
                }
                printf("\r\n");
        }
        for(int i = start; i < len; ++i)
        {
                if(num > 0 && num + sum <= target)
                {
                        num *= -1;
                        fun(sum - num, i + 1);
                        num *= -1;
                }
        }
}

void main(void)
{
        fun(0);
        system("pause");
}

国妓米兰 发表于 2012-9-21 00:16

大师应该用4维编程大法

hydranana 发表于 2012-9-21 01:42

:)hkk真码农威武。
页: [1]
查看完整版本: 简单的码农问题!!!!