Hat's Fibonacci

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 7857    Accepted Submission(s): 2553

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.
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std; //No generated Fibonacci number in excess of 2005 digits
int a[10000][260]; //260*8=2080 > 2005 不能过大 ,easy超内存
int main()
{
int i,j,n;
memset(a,0,sizeof(a));
a[1][0]=a[2][0]=a[3][0]=a[4][0]=1;
for(i=5;i<10000;i++)
{
for(j=0;j<260;j++)
a[i][j]=a[i-1][j]+a[i-2][j]+a[i-3][j]+a[i-4][j];
for(j=0;j<260;j++){
if(a[i][j]>=100000000)
{
int temp=a[i][j]/100000000;
a[i][j]=a[i][j]%100000000;
a[i][j+1]+=temp;
}
}
}
while(cin>>n){
for(i=259;i>0;i--)
if(a[n][i]!=0)
break;
cout<<a[n][i]; //最后一个数不一定是刚好8位,要单独输出。否则数的前面会出现 0000
for(j=i-1;j>=0;j--)
printf("%08d",a[n][j]); //printf("%8d",a[n][j]); 输出时会出现 空格 %08d则将空格补0
cout<<endl;
}
return 0;
}

 

HDoj-1250-Hat&#39;s Fibonacci-大数的更多相关文章

  1. hdu 1250 Hat&#39;s Fibonacci

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

  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

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

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

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

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

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

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

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

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

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

  8. 【hdoj_1250】Hat's Fibonacci(大数)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1250 思路:本题的Fibonacci数列是扩展的四阶的Fibonacci数列,用递推关系式求解即可. 题目 ...

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

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

  10. hdu 4099 Revenge of Fibonacci 大数+压位+trie

    最近手感有点差,所以做点水题来锻炼一下信心. 下周的南京区域赛估计就是我的退役赛了,bless all. Revenge of Fibonacci Time Limit: 10000/5000 MS ...

随机推荐

  1. 04XML CSS

    XML CSS 1. XML CSS <?xml-stylesheet  href ="样式表的URI"  type= "text/css" ?> ...

  2. MyEclipse2017修改Web Context Root

    1,复制一个已经存在的项目,并修改项目名 2,选中项目右键选择properities,打开. 但是这里的web context root无法修改 3,删除web显示properties的所有属性,输入 ...

  3. gym100825G. Tray Bien(轮廓线DP)

    题意:3 * N的格子 有一些点是坏的 用1X1和1X2的砖铺有多少种方法 题解:重新学了下轮廓线 写的很舒服 #include <bits/stdc++.h> using namespa ...

  4. 2018 CCPC 桂林站(upc复现赛)补题

    2018 CCPC 桂林站(upc复现赛)补题 G.Greatest Common Divisor(思维) 求相邻数的差值的gcd,对gcd分解素因子,对所有的素因子做一次遍历,找出最小答案. 几个样 ...

  5. 笔试算法题(47):简介 - B树 & B+树 & B*树

    B树(B-Tree) 1970年由R. Bayer和E. Mccreight提出的一种适用于外查找的树,一种由BST推广到多叉查找的平衡查找树,由于磁盘的操作速度远小于存储器的读写速度,所以要求在尽量 ...

  6. Excel OLE控制

    来源:http://blog.csdn.net/chelen_jak/article/details/7069095 Delphi  控制Excel(一) 使用动态创建的方法 首先创建 Excel 对 ...

  7. Linux思维导图之网络管理

    查漏补缺,理解概念,及时总结,欢迎拍砖. IP地址和MAC地址: 1.设计形态不同.IP地址是基于网络拓扑设计出来的,可以人为改动:而MAC地址是制造商烧录好的不能改动,网卡决定了MAC地址,是固定的 ...

  8. C语言学习3

    实现输入错误后重新输入 通过输入指定的行数和列数打印出二维数组对应的任一行任一列的值: #include <stdio.h> void main() { ][] = {{, , , },{ ...

  9. 远程调试nodejs

    一   windows作为远程服务器 1.在远程服务器(192.168.1.1)上安装node-inspector:npm install -g node-inspector // -g 导入安装路径 ...

  10. 【Codeforces 444A】DZY Loves Physics

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 两个点的子图他们的"密度"是比所有联通生成子图都要大的 "只要胆子大,遇到什么问题都不怕!" [代码] ...