• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            misschuer

            常用鏈接

            統計

            積分與排名

            百事通

            最新評論

            ternarysearch

            /*本算法是搜索來的, 稍加修飾了下, 貼出來, 以后容易找*/
            /* Note:Your choice is C IDE */
            #include 
            <iostream>
            #include 
            <algorithm>
            #include 
            <ctime>
            #include 
            <cstdio>
            #include 
            <cstring>
            #define N 101
            using namespace std;

            int partition(int arg[], int low, int high) {
                
                
            int x = arg[high];
                
            int i = low - 1;
                
            int ex;
                
                
            for(int j = low; j <= high - 1++ j) {
                    
                    
            if (arg[ j ] <= x) {
                        
                        i 
            ++;
                        
            if(i == j) continue ;
                        ex 
            = arg[ i ];
                        arg[ i ] 
            = arg[ j ];
                        arg[ j ] 
            = ex;
                    }
                }

                ex 
            = arg[i + 1];
                arg[i 
            + 1= arg[high];
                arg[high] 
            = ex;
                
            return i + 1;
            }

            void quickSort(int arg[], int low, int high) {
                
                
            if (low < high) {
                    
                    
            int item = partition(arg, low, high);
                    quickSort(arg, low, item 
            - 1);
                    quickSort(arg, item 
            + 1, high);
                }
            }

            int ternarySearch(int arg[], int x, int low, int high) {
                
                
            int Fpiont;
                
            int Spiont;
                
            int l = high - low ;
                
                Fpiont 
            = (high - low) / 3 + low;
                Spiont 
            = 2 * (high - low) / 3 + low;
                
                
            if(x < arg[Fpiont] && x > arg[low] && l > 3)
                    
            return ternarySearch(arg, x, low, Fpiont);
                
                
            if(x < arg[Spiont] && x > arg[Fpiont] && l > 3)
                    
            return ternarySearch(arg, x, Fpiont, Spiont);
                
                
            if(x > arg[Spiont] && x < arg[high] && l > 3)
                    
            return ternarySearch(arg, x, Spiont, high);
                
                
            if(x == arg[Spiont]) return Spiont;
                
                
            if(x == arg[Fpiont]) return Fpiont;
                
                
            if(x == arg[low]) return low;
                
                
            if(x == arg[high]) return high;
                
                
            return -1;
            }

            int main() {
                
                
            int input[N];
                
            int ans, x, i;
                
                srand( (unsigned)time( NULL ) );
                
                
            //數字最好不要重復
                for(i = 0; i < N; ++ i)
                    input[ i ] 
            = rand() % 100 ;
                
                sort(input, input 
            + N);
                
                
            for (i = 0; i < N; ++ i) printf("%d\t",input[ i ]);
                
                printf(
            "\nPlease input the number that you want to search: ");
                
                scanf(
            "%d",&x);
                
                ans 
            = ternarySearch(input, x, 0, N-1);
                
                
            if(ans == -1) printf("can't find!\n");
                
            else printf("its position is %d\n",ans + 1);
                
                puts(
            "finish!");
                
            return 0;
            }

            posted on 2011-03-17 13:09 此最相思 閱讀(165) 評論(0)  編輯 收藏 引用

            久久婷婷五月综合97色一本一本 | 亚洲午夜久久久久久久久电影网| 久久无码人妻一区二区三区午夜| 久久亚洲欧洲国产综合| 精品综合久久久久久88小说| 久久亚洲av无码精品浪潮| 久久久久久久久66精品片| 久久国产精品成人影院| 久久九九久精品国产免费直播| 亚洲日韩中文无码久久| AAA级久久久精品无码区| 久久精品国产亚洲av麻豆图片 | 国产免费久久精品丫丫| 国产精品久久久久久五月尺| 韩国无遮挡三级久久| 久久精品中文无码资源站| 久久精品无码av| 久久精品成人免费看| 色偷偷88888欧美精品久久久| 久久精品国产99久久久香蕉| 国产成人久久AV免费| 亚洲色大成网站WWW久久九九| 伊人热热久久原色播放www| 岛国搬运www久久| 青青草原1769久久免费播放| 色综合久久综合中文综合网| 中文成人久久久久影院免费观看 | 亚洲精品乱码久久久久久蜜桃| 亚洲一区中文字幕久久| 精品综合久久久久久888蜜芽| 久久亚洲熟女cc98cm| 久久亚洲精品无码aⅴ大香| 亚洲国产天堂久久久久久| 婷婷久久综合九色综合绿巨人| 成人资源影音先锋久久资源网| 久久精品国产亚洲精品2020| 三级三级久久三级久久| 亚洲国产精品成人久久| 性做久久久久久久| A狠狠久久蜜臀婷色中文网| 久久免费线看线看|