二分查找

[code] #include

int bseek(int key) { int array[10] = {1,2,3,4,5,6,7,8,9,10}; int low = 0; int high = (sizeof(array) / 4) - 1; int mid = 0; int ret = -1;

    while(low <= high) {
            mid = (low + high) / 2;
            if (key == array[mid]) {
                    ret = mid;
                    break;
            } else if (key < array[mid]) {
                    high = mid - 1;
            } else if (key > array[mid]) {
                    low = mid + 1;
            }
    }

    return ret; }

void main(int argc, char* argv[]) { printf(“key[0]:%d\n”, bseek(0)); printf(“key[1]:%d\n”, bseek(1)); printf(“key[2]:%d\n”, bseek(2)); printf(“key[3]:%d\n”, bseek(3)); printf(“key[4]:%d\n”, bseek(4)); printf(“key[5]:%d\n”, bseek(5)); printf(“key[6]:%d\n”, bseek(6)); printf(“key[7]:%d\n”, bseek(7)); printf(“key[8]:%d\n”, bseek(8)); printf(“key[9]:%d\n”, bseek(9)); printf(“key[10]:%d\n”, bseek(10)); printf(“key[11]:%d\n”, bseek(11)); }

[/code]

[code] list = [1,2,3,4,5,6,7,8,9,10] low = 0 high = len(list) - 1 idx = 0

def bseek(key): global low global high global idx while(low <= high): mid = (low + high) / 2 if (key == list[mid]): idx = mid break elif(key < list[mid]): high = mid - 1 elif(key > list[mid]): low = mid + 1

bseek(6) print idx

[/code]

糖果

糖果
LUA教程

风控管理之蜜罐

**目录**{: #toc }* TOC{:toc}# 蜜罐在风控中经常要面临这个问题:哪部分流量来自黑产?可信度高吗?这关系到现有策略效果评估、问题定位、新策略效果评估、模型训练等多个环节。解决这类问题时,蜜罐就起到了一定作用。## 什么是蜜罐?通过一些手段,引诱黑灰产...… Continue reading

Apache APISIX在SAE应用市场发布

Published on December 09, 2019

APISIX后台管理路由创建接口

Published on December 06, 2019