Problem Description
A Fibonacci sequence is calculated by
adding the previous two members the sequence, with the first two
members being both 1.

F(1) = 1, F(2) = 1, F(3) = 1,F(4) = 1, F(n>4) = F(n - 1) +
F(n-2) + F(n-3) + F(n-4)

Your task is to take a number as input, and print that Fibonacci
number.
 

Input
Each line will contain an integers.
Process to end of file.
 

Output
For each case, output the result in a
line.
 

Sample Input
100
 

Sample Output
4203968145672990846840663646
Note:
No generated Fibonacci number in excess of 2005 digits will be in the test data, ie. F(20) = 66526 has 5 digits.

纪念构建大数模板成功!!!!!(大一上学期写的,所以代码有点糙,献丑了0.0)

代码:
#include

using namespace std;

vectorv;

string big_num(string nl,string ml)

{

    //cout<<nl<<" "<<ml<<endl;

    string str="";

    int t,len,lon,j,x=1,l,m[2050],n[2050];

    memset(m,0,sizeof m);

    memset(n,0,sizeof n);

    j=0;

    len=nl.size();

    lon=ml.size();

    for(int i=len-1;i>=0;i--)

    {

        n[i]=nl[j++]-'0';

        //cout<<n[i]<<endl;

    }

    j=0;

    for(int i=lon-1;i>=0;i--)

    {

        m[i]=ml[j++]-'0';

    }

    if(len

    l=lon;

    else

    l=len;

    for(int j=0;j<=l-1;j++)

    {

        n[j]+=m[j];

        if(n[j]>=10)

        {

            n[j+1]=n[j+1]+1;

            n[j]=n[j]-10;

        }

    }

    if(n[l]==0)

    {

        //cout<<n[0]<<endl;

        for(int i=l-1;i>=0;i--)

        {

            str+=(n[i]+'0');

            //cout<<str<<endl;

            //cout<<n[i];

        }

        return str;

    }

    else

    {

        for(int i=l;i>=0;i--)

        {

            str+=(n[i]+'0');

            //cout<<str<<endl;

        }

        //cout<<n<<endl;

        return str;

    }

}

void solve()

{

    v.push_back("1");

    v.push_back("1");

    v.push_back("1");

    v.push_back("1");

    v.push_back("1");

    for(int i=5;;i++)

    {

        //cout<<v[i-1]<<" "<<v[i-2]<<" "<<v[i-3]<<" "<<v[i-4]<<endl;

        v.push_back(big_num(big_num(v[i-1],v[i-2]),big_num(v[i-3],v[i-4])));

       // cout<<"前四项为:";

        //cout<<v[i-1]<<" "<<v[i-2]<<" "<<v[i-3]<<" "<<v[i-4]<<endl;

        //cout<<"和为:";

        //cout<<v[i]<<endl;

        if(v[i].size()>2006)

            return;

    }

}

int main()

{

    //freopen("in.txt", "r", stdin);

    solve();

    int n;

    while(scanf("%d",&n)!=EOF)

    {

        //cout<<"前四项为:";

        //cout<<v[n-1]<<" "<<v[n-2]<<" "<<v[n-3]<<" "<<v[n-4]<<endl;

        //cout<<"和为:";

        cout<<v[n]<<endl;

    }

    return 0;

}


Hat's Fibonacci的更多相关文章

  1. hdu 1250 Hat's Fibonacci

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1250 Hat's Fibonacci Description A Fibonacci sequence ...

  2. Hat's Fibonacci(大数,好)

    Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  3. Hat's Fibonacci(大数加法+直接暴力)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1250 hdu1250: Hat's Fibonacci Time Limit: 2000/1000 M ...

  4. (二维数组 亿进制 或 滚动数组) Hat's Fibonacci hdu1250

    Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. HDUOJ----1250 Hat's Fibonacci

    Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  6. HDU 1250 Hat's Fibonacci(大数相加)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1250 Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Ot ...

  7. HDU 1250 Hat's Fibonacci (递推、大数加法、string)

    Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  8. hdu 1250 Hat's Fibonacci(高精度数)

    //  继续大数,哎.. Problem Description A Fibonacci sequence is calculated by adding the previous two membe ...

  9. HDOJ/HDU 1250 Hat's Fibonacci(大数~斐波拉契)

    Problem Description A Fibonacci sequence is calculated by adding the previous two members the sequen ...

  10. HDU1250:Hat's Fibonacci

    Problem Description A Fibonacci sequence is calculated by adding the previous two members the sequen ...

随机推荐

  1. 翻译 | Thingking in Redux(如果你只了解MVC)

    作者:珂珂(沪江前端开发工程师) 本文原创,转载请注明作者及出处. 原文地址:https://hackernoon.com/thinking-in-redux-when-all-youve-known ...

  2. 利用PN532读取二代证UID

    准备工作 芯片选择 NFC芯片,需要支持ISO14443 Type B协议,比如PN532 阅读ISO 14443 重点阅读如下内容: 7.3.4.1 状态转换图 7.3.5 ~ 7.3.7 REQB ...

  3. Java中的类型转换(Integer、Long、String)

    这段时间将项目中一个模块参照C++源代码,实现一个JAVA版.主要功能是将一些字段信息转换为String类型,传输后可以进行解析. Integer.Long转为String,Java本身提供了这种转换 ...

  4. 树状数组初步_ZERO

    原博客:树状数组 1 一维树状数组 1 什么是树状数组        树状数组是一个查询和修改复杂度都为log(n)的数据结构,假设数组A[1..n],那么查询A[1]+-+A[n]的时,间是log级 ...

  5. C#ZIP根据路径读取压缩包内文件数量

    /// <summary> /// 根据压缩包路径读取此压缩包内文件个数 /// </summary> /// <param name="strAimPath& ...

  6. IDEA- idea代码调试debug

    IDEA有很多的快捷键,下面整理Debug的快捷键,方便自己使用!(阅读本篇可能花费您2分钟,需要多的实践练习) F9 resume programe 恢复程序 Alt+F10 show execut ...

  7. 记XDCTF的misc之旅---base64隐写

    bWFpbigpe2ludCBpLG5bXT17KCgoMSA8PDEpPDwgKDE8PDEpPDwoMTw8Cm==ICAgICAgIDEpPDwoMTw8KDE+PjEpKSkrKCgxPDwx ...

  8. UI自动化测试(二)浏览器操作及对元素的定位方法(xpath定位和css定位详解)

    Selenium下的Webdriver工具支持FireFox(geckodriver). IE(InternetExplorerDriver).Chrome(ChromeDriver). Opera( ...

  9. 简易RPC框架-过滤器机制

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...

  10. Python自学笔记-进程,线程(Mr serven)

    对于操作系统来说,一个任务就是一个进程(Process),比如打开一个浏览器就是启动一个浏览器进程,打开一个记事本就启动了一个记事本进程,打开两个记事本就启动了两个记事本进程,打开一个Word就启动了 ...