回 帖 发 新 帖 刷新版面

主题:第50次编程比赛结果

我首先谢谢大家的捧场和支持,重在参与,相信大家都很有收获。

第一轮先测试所有代码的正确性,筛走结果不正确的,有溢出现象的,不符合函数接口的,死循环的等等

后面的第二轮则是测试所以正确代码的运行速度。
丑媳妇总要见公婆,我的测试代码很简陋:(,请大家多多包涵

#include <stdio.h>
#include <time.h>
#include <stdlib.h>

#define MAX_SIZE     ( 50 )
#define N            ( 5 )
#define TEST_COUNT   ( 1e6 )

typedef long long INT64;

void HeroNeedThree(INT64* subset, unsigned int n);

int main(int argc, char *argv[])
{
        INT64 subset[MAX_SIZE];
        clock_t start, end;
        int test_data[] = { 1, 1e3, 1e6, 2221+1, 4999999+1,
                            0x100000, 0x1000000, 0x10000000, 0xFFFFFFFF, 0 };
        int i, j, k;
        

        for (i = 0; test_data[i] > 0; ++i)
        {
                printf( "%d\t", i );
                for ( j = 0; j < N; ++j)
                {
                        start = clock();
                        for ( k = 0; k < TEST_COUNT; ++k )
                        {
                                HeroNeedThree( subset, test_data[i] );
                        }
                        end = clock();
                        printf( "%d\t", (int)(end - start) );
                }
                printf( "\n" );
        }
        system( "pause" );
        return 0;
}

下面是每个人的测试结果:

3楼 雨中飞燕
0       0       15      16      15      16
1       203     203     219     203     203
2       359     360     359     359     375
3       219     203     219     203     219
4       406     422     438     437     406
5       453     438     453     438     453
6       531     531     547     531     532
7       625     625     625     625     625
请按任意键继续. . .

8楼 renew
0       15      16      15      16      16
1       140     125     141     125     141
2       250     250     250     234     250
3       125     125     125     109     125
4       282     265     266     281     266
5       281     297     297     281     297
6       328     344     328     344     343
7       391     406     406     391     406
请按任意键继续. . .

12楼 poorb
0       15      31      16      16      31
1       531     531     516     516     531
2       1391    1375    1390    1391    1390
3       469     469     469     468     469
4       1485    1500    1484    1484    1485
5       1765    1750    1797    1735    1734
6       2609    2610    2625    2609    2625
7       3641    3672    3656    3640    3672
请按任意键继续. . .

15楼 euc
0       250     234     250     234     250
1       282     265     281     282     265
2       297     297     313     296     297
3       250     266     266     265     266
4       281     297     281     297     281
5       344     344     344     328     343
6       344     344     344     359     344
7       375     359     360     359     359
请按任意键继续. . .

16楼 ghbxx2004
0       31      15      32      15      16
1       234     219     234     204     218
2       391     375     391     375     390
3       203     219     203     203     203
4       438     422     422     437     406
5       500     500     485     515     485
6       594     578     593     579     593
7       672     688     672     687     688
请按任意键继续. . .

19楼 eastcowboy
0       31      31      31      32      15
1       219     219     218     204     234
2       391     390     406     391     391
3       203     203     203     203     203
4       438     437     438     422     437
5       500     485     484     500     484
6       578     579     562     578     578
7       672     672     672     672     656
请按任意键继续. . .

20楼 iAkiak
0       359     344     359     359     360
1       750     750     750     765     750
2       954     953     937     953     953
3       672     657     671     672     672
4       1016    1031    1016    1000    1031
5       1422    1422    1422    1437    1406
6       1610    1625    1625    1609    1609
7       1829    1812    1813    1828    1812
请按任意键继续. . .

21楼 rickone
0       125     140     141     125     125
1       234     203     203     204     218
2       250     250     250     250     266
3       187     188     187     203     188
4       265     250     235     265     266
5       281     297     281     282     281
6       297     312     313     297     297
7       313     312     313     312     313
请按任意键继续. . .

22楼 medie2005
0       218     203     204     187     203
1       563     562     578     563     562
2       1422    1406    1438    1406    1406
3       485     484     469     484     469
4       1484    1469    1485    1500    1468
5       2094    2109    2094    2094    2094
6       2937    2953    2953    2922    2938
7       3969    3953    3968    3938    3984
请按任意键继续. . .

24楼 Kummerwu
0       125     125     110     125     109
1       250     250     250     234     250
2       297     297     297     297     312
3       203     204     187     203     203
4       313     281     313     296     297
5       360     375     359     375     375
6       406     407     406     437     407
7       437     422     422     437     422
请按任意键继续. . .

26楼 xchbcahz
0       15      0       16      15      32
1       1609    1625    1609    1594    1610
2       4328    4359    4328    4328    4328
3       1141    1109    1125    1125    1125
4       4704    4703    4718    4704    4718
5       7719    7688    7718    7703    7750
6       11110   11062   11032   11062   11078
7       14985   14984   14953   14984   15016

29楼 wuchengwei
0       15      0       16      15      32
1       2047    2062    2047    2031    2047
2       3078    3078    3063    3078    3047
3       1656    1672    1672    1672    1672
4       3250    3250    3250    3250    3250
5       4890    4891    4890    4907    4906
6       5766    5781    5781    5797    5781
7       6688    6687    6688    6687    6703


34楼 forjane
0       125     125     109     125     125
1       203     203     203     203     204
2       265     250     266     265     266
3       188     171     172     188     172
4       234     250     266     250     250
5       297     296     297     297     297
6       297     312     313     312     313
7       312     313     312     313     312
请按任意键继续. . .

39楼 BigCarrot
0       16      15      32      15      16
1       219     203     219     203     203
2       375     375     375     375     375
3       219     203     218     204     218
4       422     422     438     421     422
5       453     469     453     453     438
6       531     531     547     532     531
7       625     609     625     610     625
请按任意键继续. . .

41楼 wangfangbob
0       215     216     215     200     232
1       340     325     341     325     341
2       434     403     419     419     418
3       310     309     325     309     325
4       466     434     435     434     435
5       512     497     497     497     497
6       559     559     560     543     560
7       606     606     622     606     607
请按任意键继续. . .

43楼 szh
0       15      0       16      15      16
1       344     328     344     343     344
2       641     640     641     625     625
3       281     282     281     265     282
4       687     688     703     672     687
5       1110    1109    1109    1110    1109
6       1438    1468    1469    1438    1468
7       1844    1828    1844    1828    1844
请按任意键继续. . .

45 楼天边蓝
0       125     125     140     110     140
1       2047    2063    2062    2047    2062
2       3032    3015    3032    3000    3031
3       1672    1656    1672    1656    1656
4       3219    3547    3234    3235    3218
5       4672    4672    4641    4656    4656
6       5516    5516    5531    5531    5516
7       6406    6406    6391    6406    6422
请按任意键继续. . .

比较突出的就是8楼,15楼,21楼 24楼 34楼
其中8楼不仅对大N速度很快,当N较小时效率也很快,并且位移的手法很巧妙,所以第50次编程比赛的冠军就是[color=FF0000][size=3]renew[/size][/color],大家祝贺一下他。
第51次编程比赛由renew来主持,请大家多多支持。

回复列表 (共33个回复)

31 楼

//非常精确
QueryPerformanceFrequency()
QueryPerformanceCounter()


//查询进程相关时间
GetProcessTimes()

32 楼

void HeroNeedThree(INT64* subset, unsigned int n)
{
    int exp = 0;
    INT64 element = 1;
    unsigned int combineNum = 1;
    unsigned int nNext = n;
    while ((n / 2) != 0)
    {
        exp++;
        element *= 3;
        combineNum *= 2;
        n /= 2;
    }
    nNext -= combineNum;

    if (nNext == 0)//in this case, we find all.
    {
        int index = *subset + 1;
        while (index < (*subset + exp + 1))
        {
            element /= 3;
            subset[index++] = element;
        }
        *subset += exp;//subset[0] is original Num,it should be added exp.
        return;
    }
    else
    {
        *subset += 1;// find one .store Num in subset[0].
        subset[*subset] = element;
        HeroNeedThree(subset, nNext);//continue to find the next one.
    }
}
LZ帮我看下代码那里出问题了 ?我自己看不出来啊。。。(只知道自己的代码很慢)
//int index = *subset + 1; 这一句将_int64转为int,可能会丢失数据。但是元素数不超过50啊,应该没有问题啊。。。。

33 楼

辛苦了!

我来回复

您尚未登录,请登录后再回复。点此登录或注册