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. XML(二)之DTD——XML文件约束

    前面介绍了XML的作用和基本的格式,今天我给大家分享的是关于XML的约束.废话不多说,我们直接来正题! 一.DTD简介 1.1.DTD概述 DTD(Document Type Definition,文 ...

  2. Codeforce E. Fire

    E. Fire time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...

  3. 九月 26, 2017 10:18:14 上午 com.sun.jersey.server.impl.application.RootResourceUriRules <init> 严重: The ResourceConfig instance does not contain any root resource classes.

    Tomcat启动错误:九月 26, 2017 10:18:14 上午 com.sun.jersey.server.impl.application.RootResourceUriRules <i ...

  4. Linux入门之常用命令(14) kill

    Linux kill 命令使用详解 功能说明:删除执行中的程序或工作. 语 法:kill [-s <信息名称或编号>][程序] 或 kill [-l <信息编号>] 补充说明: ...

  5. ArrayList , Vector 数组集合

    ArrayList 的一些认识: 非线程安全的动态数组(Array升级版),支持动态扩容 实现 List 接口.底层使用数组保存所有元素,其操作基本上是对数组的操作,允许null值 实现了 Randm ...

  6. PIC32MZ 通过USB在线升级 -- USB HID bootloader

    了解 bootloader 的实现, 请加QQ: 1273623966(验证填bootloader); 欢迎咨询或定制bootloader; 我的博客主页 www.cnblogs.com/geekyg ...

  7. java关键字中文对比

    abstract 摘要|抽象assert 声称boolean 布尔break 中断byte 字节case 实例catch 捕捉char 烧焦class 类const 常量continue 持续defa ...

  8. DB2插入数据 sqlcode302 sqlstate22001错误如何解决?

    总结:出现这种错误的原因主要是,插入数据时的长度和数据库中定义的长度不匹配或超出限制.

  9. ch3-模板语法({{}} v-html v-bind:id 表达式 指令 修饰符 过滤器)

    1 模板语法 Vue.js 使用了基于 HTML 的模版语法,允许开发者声明式地将 DOM 绑定至底层 Vue 实例的数据. 所有 Vue.js 的模板都是合法的 HTML ,所以能被遵循规范的浏览器 ...

  10. 轻量级文本编辑器,Notepad最佳替代品:Notepad++

    目录 正文之前 1. 目的 2. 原帖 3. 为何推荐Notepad++ 3.1. Notepad++的一些基本特点 3.2. notepad,notepad2,notepad++,ultraEdit ...