模板【斐波那契数列】done

PART1(算法思想简介

1.实现、dalao分析

dalao

2.时间复杂度

3.适用情况、特别优势需要注意的点

4.函数、变量名的解释+英文

PART2(算法各种类型 并 附上代码

1.

实现:通项公式,f1 = f2 = 1;

复杂度:log(n)

#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
double pow(double x, long n)
{
    double res = 1.0;
    double x_contribution = x;
    while(n>0)
    {
        if((n&1)==1)
            res*=x_contribution;
        x_contribution *= x_contribution;
        n=n>>1;
    }
    return res;
}
double myPow(double x, int n)
{
    long b = n; //防止执行n=-n时数组越界
    return b<0 ? 1.0/pow(x,-b) : pow(x,b);
}
int climbStairs(int n)
{
    return (int)((myPow((1+sqrt(5))/2,n)-myPow((1-sqrt(5))/2,n))/sqrt(5));
}
int main()
{
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cout <<climbStairs(i)<<endl;
    }
    return 0;
}
View Code

PART3(算法的延伸应用、深度的理解、相关的有趣题目

 

posted @ 2021-08-04 14:39  bear_xin  阅读(69)  评论(0)    收藏  举报