Hat's Fibonacci(大数)
来源:互联网 发布:校园网mac地址绑定错误 编辑:程序博客网 时间:2024/06/06 02:21
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.
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
4203968145672990846840663646Note:No generated Fibonacci number in excess of 2005 digits will be in the test data, ie. F(20) = 66526 has 5 digits.
Author
戴帽子的
Recommend
Ignatius.L
题目给出公式
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),然后给出n,要求出F[n],数据比较大,要用到大数运算
代码:
#include<iostream>#include<cstdlib>#include<cstring>#include<algorithm>#include<cstdio>using namespace std;int f[4][2101];int ans[2101];int main(){ int N; while(cin>>N) { if(N<=4) { cout<<"1"<<endl; continue; } memset(f,0,sizeof (f)); memset(ans,0,sizeof (ans)); f[0][0]=f[1][0]=f[2][0]=f[3][0]=1; int len=1; for(int i=4;i<N;i++) { int carry=0; for(int j=0;j<len;j++) { int temp=carry+f[0][j]+f[1][j]+f[2][j]+f[3][j]; ans[j]=temp%10; carry=temp/10; } while(carry!=0) { ans[len++]=carry%10; carry/=10; } for(int j=0;j<len;j++) { f[i%4][j]=ans[j]; } } for(int i=len-1;i>=0;i--) cout<<ans[i]; cout<<endl; }}学 java啊 学 java 啊!!!!!!!!!!!!!!!!!!!
阅读全文
0 0
- Hat's Fibonacci(大数)
- HDU1250~Hat's Fibonacci(大数加法)
- HDU 1250-Hat's Fibonacci(大数)
- Hat's Fibonacci(JAVA大数)
- HDU1250 Hat's Fibonacci 【大数】
- 【hdoj_1250】Hat's Fibonacci(大数)
- HDU1250 Hat's Fibonacci(大数)
- hdu 1250 Hat's Fibonacci (大数相加,水题)
- hdu 1250 Hat's Fibonacci(大数加法)
- HDU 1250 Hat's Fibonacci(Java大数相加)+讲解
- hdu 1250 Hat's Fibonacci (Java大数)
- HDU 1250 Hat's Fibonacci(大数相加)
- HDOJ 1250 Hat's Fibonacci (大数的加法)
- hdu 1250 Hat's Fibonacci(java大数)
- HDU1250 Hat's Fibonacci 大数运算
- 【大数问题】 HDOJ 1250 Hat's Fibonacci
- hdu 1250 Hat's Fibonacci (大数相加)
- HDoj-1250-Hat's Fibonacci-大数
- 如何给运行的tomcat指定特定的jdk版本以及验证
- 【剑指offer-解题系列(41)】和为S的连续正数序列
- 461. Hamming Distance
- jquery框架学习(keep update)
- 地图下载器破解版之太乐地图下载器4.9 破解教程(破解安装包见上传资源)
- Hat's Fibonacci(大数)
- JavaScript DOM对象
- (192)纹理处理
- CCF认证模拟题——学生排队
- kaggle竞赛学习笔记:EDA 和 preprocessing
- C语言编程之深刻理解计算机中的进制01
- SDIO驱动(14)card的CIS读取及解析
- 自定义MVC
- BZOJ 3697: 采药人的路径 树的点分治