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. ngx_lua实现登录逻辑

    最近在公司做一个简单的portal,本来很简单的,只用ngx_lua就可以实现所有的业务逻辑,不需要upstream上游服务.但被要求接入公司内部的用户校验系统,说白了就是一个登录过程,只允许公司内部 ...

  2. IDEA的注册

    步骤: license server -> 属性 -> 允许作为程序执行文件 即 chmod 777

  3. SVN使用小结

    SVN是Subversion的简称.是一个开放源码的版本号控制系统.在它的管理下,文件和文件夹能够超越时空的限制,权且当作一种奇妙的"时间机器"吧. 基本功能 版本号控制 作为一个 ...

  4. [开发工具]_[VS2010]_[vs2010的一个bug-使用stringstream时出现]

    1. 注冊Microsfot之后想提交bug, 发现有这个提示, 所以提交不了bug, 有能提交的提交下吧. You are not authorized to submit the feedback ...

  5. Objective-C:NSNumber类的常见用法

    NSNumber基本数据类型包装类: // //  main.m //  04-NSNumber // //  Created by ma c on 15/8/17. //  Copyright (c ...

  6. Longest Substring Without Repeating Characters leetcode java

    题目: Given a string, find the length of the longest substring without repeating characters. For examp ...

  7. 任务栈 启动模式 Task Flag launchMode MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  8. C#全屏截图

    Image baseImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); ...

  9. php CURL 请求头和响应头获取

    1.从CURL中获取响应头 $oCurl = curl_init(); // 设置请求头, 有时候需要,有时候不用,看请求网址是否有对应的要求 $header[] = "Content-ty ...

  10. (转)[unity3d]easytouch的使用

    对于移动平台上的RPG类的游戏,我们常用虚拟摇杆来控制人物角色的行走和一些行为,相信我们对它并不陌生,之前尝试了EasyTouch2.5,发现并没有最新版的3.1好用,2.5版本的对于自适应没有做的很 ...