利用查找表的思想解决数据分类与缩减问题

本文介绍了一种将0到360范围内的任意数n分配至72个数组(每组含5个不同元素)的算法。通过n除以5确定其在m数组中的位置,m数组包含72个子数组名称,此方法实现数据的有效分类。

问题:将0~360中任意一个数n,放入72个数组(每个数组的数组成员都为5个不同的数)中的一个。

 

我们可以先定义一个数组m[72],里面72个变量分别对应72个数组名,我们用n/5得到n对应的m数组中存储的数组名即m[n/5].

 

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

typedef int(*M)[int];

M m[72]={.......................};

//调用72个数组

m[n/5][i] = n;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// the versions to be tested
    typedef void(*FunctionPointer)(cv::Mat, int);
    FunctionPointer functions[NTESTS] = { colorReduce, colorReduce1, colorReduce2, colorReduce3, colorReduce4,
                                          colorReduce5, colorReduce6, colorReduce7, colorReduce8, colorReduce9,
                                          colorReduce10, colorReduce11, colorReduce12, colorReduce13, colorReduce14};
    // repeat the tests several times
    int n = NITERATIONS;
    for (int k = 0; k<n; k++) {

        std::cout << k << " of " << n << std::endl;

        // test each version
        for (int c = 0; c < NTESTS; c++) {

            images[c] = cv::imread("boldt.jpg");

            // set timer and call function
            tinit = cv::getTickCount();
            functions[c](images[c], 64);
            t[c] += cv::getTickCount() - tinit;

            std::cout << ".";
        }

        std::cout << std::endl;
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值