Hat's Fibonacci

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5800    Accepted Submission(s): 1926

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
戴帽子的
 
Recommend
Ignatius.L
 
 大数题,我先是用打表的方法,发现数字到达7037的时候,数字规模才能达到2005 ...然后用7037*2005 ---->已经超过内存,所以这条路实不可取的。。。唯一的方法,只好暴力法,但又担心会超时,可是,喜感就是,竟然过了,还应458ms。。。。哎!!!。
贴下代码:
   #include<stdio.h>
#include<string.h>
#define maxn 2006
int a[maxn],b[maxn],c[maxn],d[maxn],ans[maxn];
int main()
{
int i,j,e,s,up,num;
while(scanf("%d",&num)!=EOF)
{
if(num<=)
printf("");
else
{
memset(a,,sizeof a);
memset(b,,sizeof b);
memset(c,,sizeof c);
memset(d,,sizeof d);
memset(ans,,sizeof ans);
a[]=b[]=c[]=d[]=;
for(i=,up=;i<num;i++)
{
for(j=,e=;j<=up;j++)
{
s=a[j]+b[j]+c[j]+d[j]+e;
ans[j]=s%;
e=(s-ans[j])/;
if(s>&&j==up) up++;
a[j]=b[j];
b[j]=c[j];
c[j]=d[j];
d[j]=ans[j];
}
}
for(j=maxn;ans[j]==;j--);
for(i=j;i>=;i--)
{
printf("%d",ans[i]);
}
}
printf("\n");
}
return ;
}

HDUOJ----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 membe ...

  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(高精度)

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

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

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

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

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

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

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

随机推荐

  1. 进程外Session保存和全局文件错误捕获

    Session深入学习,进程外的Session 当用户登入页面跳转时候,我们会将用户登录信息保存在服务端一个键值对的Session(Session池)中.那么Session池又是在哪里呢? 它最终默认 ...

  2. Gunicorn+Flask中重复启动后台线程问题

    假设程序如下: if __name__ == '__main__': t = Thread(target=test) t.start() app.run(host='0.0.0.0',port=808 ...

  3. C语言:返回两个数组中第一个元素的指针,并输出这个值

    // //  main.c //  Pointer_search // //  Created by ma c on 15/8/2. //  Copyright (c) 2015年. All righ ...

  4. Objective-C:三种文件导入的方式比较

    三种文件导入的方式比较:   类的前项声明@class.import.include:   1.采用@class 类名的方式,它会告诉编译器有这么一个类,目前不需要知道它内部的实例变量和方法是如何定义 ...

  5. 拍案惊奇!9款神奇的jQuery/CSS3经典插件

    款非常给力的jQuery/CSS3经典插件,插件包括CSS3图片特效.jQuery动画菜单.jQuery时尚登录表单等,一起来看看这些jQuery插件. .CSS3图片重力感应特效 这是一款应用重力感 ...

  6. WordPress 无法使用the_content()方法输出内容

    在使用WordPress里在一个页面里我使用the_content()方法来输出当前页面的内容,但却显示为空,而标题,url等都没有问题 在网络上好像遇到这种情况的人很少只找到了一个说是可能是func ...

  7. [Javascript] Prototype 1

    You can add prototype to any object in Jacascript likes Object, Array, String... prototype 有继承的作用,比如 ...

  8. [Javascipt] Immediately-Invoker 2

    Now the people at Poplar Puzzles would like you to treat an array of functions like a Queue, passing ...

  9. URL参数转换对象

    var parseQueryString = function (url) { var reg_url = /^[^\?]+\?([\w\W]+)$/, reg_para = /([^&=]+ ...

  10. 在Fedora10上安装MySQL5.0.18,告捷!

    又一次安MySQL了,为什么又呢,因为前面成功那次算配置,即配置Fedora10自带的MySQL,这个还不算自己安装的,所以有必要再安装一次,以后还装也有可能,换操作系统,换MySql版本都可能这样做 ...