UVALive 8292 二分法裡數列

2021-08-25 02:43:04 字數 555 閱讀 8119

如圖的數列就是法里數列

特點是分子分母互質

這個題其實就是尋找最逼近乙個浮點數的法里數

法里數的產生:

假設已知兩個法里數a/b和c/d,那麼兩者之間的法里數就是(a+c)/(b+d)

#include #include #include #include #include #include #include #include using namespace std;

int t,k,m;

double x;

int main()

else

}printf("%d ",k);

if(fabs(1.0*a/b-x)>fabs(1.0*c/d-x))

printf("%d/%d\n",c,d);

else

printf("%d/%d\n",a,b);

}return 0;

}

C 二分法查詢,遞迴二分法

用二分法來求需要查詢的值.includeusing namespace std 查詢key元素是否存在 int findkey const int buf 100 const int ilen,const int key else right left mid 1 查詢失敗 return 1 查詢k...

python二分法查詢 Python 二分法查詢

二分法查詢主要的作用就是查詢元素 lst 1,3,5,7,12,36,68,79 資料集 百萬級資料 num int input 請輸入你要查詢的元素資訊 for el in lst if num el print 存在 break else print 不存在 len lst 0 1 2 3 4 ...

二分法,二分搜尋

二分法是乙個應用很廣泛的演算法 好吧,剛說出這句話的時候,我查了一下資料,發現我了解的應用寥寥無幾.ok,既然不知道,那就下次補充把。咱們直接進入主題。二分法 bisection method 是一種方程式根的近似值求法。演算法 若要求已知函式f x 0的值則 1.先找出乙個區間 a,b 使得f a...