//  继续大数,哎、、

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.
 
Author
戴帽子的
 

/**************************************

模拟斐波那契数列 , 不过递推公式变成了 f1 = f2 = f3 = f4 = 1 ,  f(n) = f(n-1) + f(n-2) + f(n-3) +f(n-4) . (n>=5)  , 最大的数有2005位,所以,用大数吧

用的 跟 hdu1042 N! 的方法一样,用 十万 进制解决,每个整形存 10000,当然更大点也可以。。

**************************************/

Code:

#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
const int N = 7500;
const int M = 500;
int num[N][M];
void add()
{
memset(num,0,sizeof(num));
num[1][1] = num[2][1] = num[3][1] = num[4][1] = 1;
int i,j,k = 0;
for(i = 5;i<7500;i++)
for(j = 1;j<500;j++)
{
k += num[i-1][j] + num[i-2][j] + num[i-3][j] + num[i-4][j];// 递推公式
num[i][j] = k%100000;
k = k/100000;
}
while(k)
{
num[i][j++] = k%100000;
k = k/100000;
}
}
int main()
{
int n,i;
add();
while(cin>>n)
{
for(i = 500-1;i>=0;i--)
{
if(num[n][i]!=0)
break;
}
printf("%d",num[n][i--]);
while(i>0)
printf("%05d",num[n][i--]);
printf("\n");
}
return 0;
}

hdu 1250 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. HDU 1250 Hat's Fibonacci(大数相加)

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

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

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

  4. HDU 1250 Hat's Fibonacci(高精度)

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

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

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

  6. hdu 1250 Hat's Fibonacci(java,简单,大数)

    题目 java做大数的题,真的是神器,来一道,秒一道~~~ import java.io.*; import java.util.*; import java.math.*; public class ...

  7. hdu 1250 Hat&#39;s Fibonacci

    pid=1250">点击此处就可以传送hdu 1250 Problem Description A Fibonacci sequence is calculated by adding ...

  8. hdu 1715 大菲波数(高精度数)

    Problem Description Fibonacci数列,定义如下: f(1)=f(2)=1 f(n)=f(n-1)+f(n-2) n>=3. 计算第n项Fibonacci数值. Inpu ...

  9. HDU 4099 Revenge of Fibonacci(高精度+字典树)

    题意:对给定前缀(长度不超过40),找到一个最小的n,使得Fibonacci(n)前缀与给定前缀相同,如果在[0,99999]内找不到解,输出-1. 思路:用高精度加法计算斐波那契数列,因为给定前缀长 ...

随机推荐

  1. C#基础知识回顾-- 反射(3)

    C#基础知识回顾-- 反射(3)   获取Type对象的构造函数: 前一篇因为篇幅问题因为篇幅太短被移除首页,反射这一块还有一篇“怎样在程序集中使用反射”, 其他没有什么可以写的了,前两篇主要是铺垫, ...

  2. .Net Core-TagHelpers-Environment

    当我们新建一个.net core项目时,发现页面中有个奇怪的TagHelper元素,如下:     <environment names="Development"> ...

  3. JavaScript toFixed() 方法

    定义和用法toFixed() 方法可把 Number 四舍五入为指定小数位数的数字. 语法NumberObject.toFixed(num) 参数 描述num 必需.规定小数的位数,是 0 ~ 20 ...

  4. Codeforces Round #325 (Div. 2) A. Alena's Schedule 水题

    A. Alena's Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/pr ...

  5. Codeforces Round #323 (Div. 2) C. GCD Table 暴力

    C. GCD Table Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/583/problem/C ...

  6. node.js在windows下的学习笔记(9)---文件I/O模块

    开发中我们经常会有文件I/O的需求,node.js中提供一个名为fs的模块来支持I/O操作,fs模块的文件I/O是对标准POSIX函数的简单封装. 1.将"hello world" ...

  7. 插头dp的几个模板

    /* ural1519 求经过全部可行点的哈密顿回路的个数 括号匹配法,转移有点复杂,可是时间空间比較小 */ #include<cstdio> #include<cstring&g ...

  8. 区域医疗移动医疗影像解决方案2--基于FLEX的PACS

    基于Flex的PACS和基于HTML5的PACS,都不是基于DICOM的WADO的方式,即所有的图像操作,移动.缩放.旋转.测量.伪彩.窗宽窗位调整等都是在本地浏览器能够完成,不用和服务器进行频繁的交 ...

  9. SQL Server 性能优化3 该指数(Index)保养

    前言 之前的一篇文章介绍了索引来提高数据库的查询性能,这其实仅仅是个开始.也许假设缺乏适当的保养,索引你以前建立的,甚至成为拖累,成为帮凶下降数据库的性能. 寻找碎片 消除碎片索引维护可能是最常规的任 ...

  10. OSI七层模型具体解释

    OSI 七层模型通过七个层次化的结构模型使不同的系统不同的网络之间实现可靠的通讯,因此其最基本的功能就是帮助不同类型的主机实现传输数据 . 完毕中继功能的节点通常称为中继系统.在OSI七层模型中,处于 ...