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 <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <malloc.h>
using namespace std;
void add(char* a,char* b,char* c)
{
int i,j,k,max,min,n,temp;
char *s,*pmax,*pmin;
max=strlen(a);
min=strlen(b);
if (max<min)
{
temp=max;
max=min;
min=temp;
pmax=b;
pmin=a;
}
else
{
pmax=a;
pmin=b;
}
s=(char*)malloc(sizeof(char)*(max+1));
s[0]='0';
for (i=min-1,j=max-1,k=max; i>=0; i--,j--,k--)
s[k]=pmin[i]-'0'+pmax[j];
for (; j>=0; j--,k--)
s[k]=pmax[j];
for (i=max; i>=0; i--)
if (s[i]>'9')
{
s[i]-=10;
s[i-1]++;
}
if (s[0]=='0')
{
for (i=0; i<=max; i++)
c[i-1]=s[i];
c[i-1]='\0';
}
else
{
for (i=0; i<=max; i++)
c[i]=s[i];
c[i]='\0';
}
free(s);
}
char a[8001][2505];
int main(void)
{
int n,i;
for(i=1; i<=4; i++)
strcpy(a[i],"1");
for(i=5; i<=8000; i++)
{
char c[2505],b[2505];
add(a[i-1],a[i-2],c);
add(a[i-3],a[i-4],b);
add(b,c,a[i]);
}
while(cin>>n)
{
cout<<a[n]<<endl;
}
return 0;
}

HDU1250:Hat's Fibonacci的更多相关文章

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

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

  2. (二维数组 亿进制 或 滚动数组) Hat's Fibonacci hdu1250

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

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

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

  4. HDUOJ----1250 Hat's Fibonacci

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

  5. HDU 1250 Hat's Fibonacci(大数相加)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1250 Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Ot ...

  6. hdu 1250 Hat's Fibonacci

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

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

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

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

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

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

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

随机推荐

  1. sql CAST用法

    (1).CAST()函数的参数是一个表达式,它包括用AS关键字分隔的源值和目标数据类型.以下例子用于将文本字符串'12'转换为整型: ' AS int) (2).返回值是整型值12.如果试图将一个代表 ...

  2. ios jsbrige

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  3. hadoop源码eclipse环境搭建-源码获取阶段

    就目前了解,结合eclipse阅读和编译hadoop源码用两种方式:svn和git. 根据官方指南http://wiki.apache.org/hadoop/EclipseEnvironment 推荐 ...

  4. poj1665

    #include <stdio.h> #include <stdlib.h> #define pi 3.1415926 int main() { float dia,tim; ...

  5. ubuntu下编译内核驱动。

    目的: 1. 驱动热身.网上有很多类似的文章可供参考. 2. 在操作系统中, 编写这个设备的驱动. 3. 为写qemu的watchdog驱动练手. 有朋友问make的 watchdog驱动 需要什么准 ...

  6. [虚拟化/云][全栈demo] 为qemu增加一个PCI的watchdog外设(三)

    我们已经设计了一个基于qemu的watchdog了.下一步工作就是创建一个含有我们的watchdog的虚拟计算机器了. 准备工作: 1. 使用virt-manager或者virsh创建一个虚拟机器. ...

  7. Objective-C官方文档翻译 Block

    版权声明:原创作品,谢绝转载!否则将追究法律责任. 一个Objective-c类定义了一个对象结合数据相关的行为.有时候,这使得他有意义的表达单个任务或者单元的行为.而不是集合的方法. blocks是 ...

  8. Java 中的resultset详解

    结果集(ResultSet)是数据中查询结果返回的一种对象,可以说结果集是一个存储查询结果的对象,但是结果集并不仅仅具有存储的功能,他同时还具有操纵数据的功能,可能完成对数据的更新等. 结果集读取数据 ...

  9. Android 创建目录

    //android 内部存储自定义目录写入文件 try{ File testDir = new File(this.getFilesDir().getAbsolutePath() + File.sep ...

  10. URL编码解码

    ios url 编码和解码 1.url编码 ios中http请求遇到汉字的时候或者像是%…@#¥%&*这些字符的时候也可以使用下面的方法,需要转化成UTF-8,用到的方法是: NSString ...