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. Unity3d-Particle System 5.x系统的学习(四)

    Unity3d-Particle System 5.x系统的学习(四) 今天,我们来聊聊unity5.x的粒子系统和unity4.x粒子系统的区别. 我大致看了下,区别还是蛮多的,但是总体的粒子制作思 ...

  2. 用java解析在OpenStreetMap上下载的地图数据(SAX版,适合比较大的xml文件)

    java程序如下: package gao.map.preprocess; import java.io.BufferedWriter; import java.io.File; import jav ...

  3. Ubuntu 12.04 安装配置 Apache2

    Apache2安装 1 我们使用root账户进行安装,首先切换到root账户,输入命令: sudo su 2 安装 Apache2 apt-get install apache2 在浏览器输入你服务器 ...

  4. go语言之进阶篇同名字段

    1.同名字段 示例: package main import "fmt" type Person struct { name string //名字 sex byte //性别, ...

  5. Android数据展示之ListView

    Android应用程序中经常需要使用ListView展示数据,一个ListView通常将数据填充到布局文件中,在填充的过程中需要知道连接数据与ListView的适配器.适配器是一个连接数据和Adapt ...

  6. 超酷的响应式dribbble设计作品瀑布流布局效果

    相信做设计的朋友肯定都知道dribbble.com,它是一个非常棒的设计师分享作品的网站,全世界数以万计的设计高手和行家都在这个网站上分享自己的作品,当然,如果你常在上面闲逛的话,经常得到一些免费的好 ...

  7. 【BZOJ2662】【BeiJing wc2012】冻结 分层图 裸的!

    我都不好意思发题解了,看这篇博吧.(飞行路线的,基本一样) http://blog.csdn.net/vmurder/article/details/40075989 同学做了好久.我害怕题里有坑,又 ...

  8. Mac 显示和隐藏文件

    显示和隐藏文件 显示Mac隐藏文件的命令: defaults write com.apple.finder AppleShowAllFiles -bool true 隐藏Mac隐藏文件的命令: def ...

  9. 重装上了Fedora8自带的MySQL5.0.45,再试,告捷!!

    MySql服务器IP是192.168.0.104,测试连接的笔记本IP为192.168.0.100. 以下命令说明两台机器的网络连接是通畅的: [root@bogon bin]# ping 192.1 ...

  10. C#.NET常见问题(FAQ)-如何清空stringbuilder

    就红色的代码可以: System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("hello" ...