#include<iostream>#include<vector>usingnamespace std;using Rank =int;classFib{private:Rank g ,f;public:Fib(Rank n){f =0; g=1;//f 代表 fib(k -1) g 代表 fib(k)while(0< n--){g = g + f;f = g - f;}}Rank get(){return g;}Rank next(){g = g + f;f = g -f;return g;};Rank pre(){f = g-f;g = g-f;return g;}};template<typenameT>static Rank fibSearch(T *A,const T &e,Rank lo,Rank hi){for(Fib fib(hi - lo); lo < hi;){while( hi -lo < fib.get()) fib.pre();Rank mi = lo + fib.get()-1;(e < A[mi])? hi = mi : lo = mi +1;}return lo -1;}intmain(){std::vector<Rank> test{1,3,6,8,9,11,13,17,20};Rank index = fibSearch<Rank>(test.data(),14,0,test.size());cout <<"index: "<< index <<endl;return0;}
相关文献
Generalizing from a Few Examples: A Survey on Few-Shot Learning
Author: YAQING WANG、QUANMING YAO、JAMES T. KWOK、LIONEL M. NIAbstract: Artificial intelligence succeeds in data-intensive applications, but it lacks the ability of learning from a …
从零开始的 Hugging Face 项目:我的首个在线 SQL 查询工具之旅
作为一名 AI 初学者,我最近完成了一个意义非凡的项目:在 Hugging Face Spaces 上构建了一个简单却实用的在线 SQL 查询工具。这个项目不仅让我了解了 Hugging Face 平台的核心功…