传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1250

Hat's Fibonacci

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

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
戴帽子的
 
分析:
大数相加的模板题!
 
code:
#include<bits/stdc++.h>
using namespace std;
#define max_v 10005 string add(string s1,string s2) { if(s1.length()<s2.length()) { string temp=s1; s1=s2; s2=temp; } int i,j; for(i=s1.length()-,j=s2.length()-;i>=;i--,j--) { s1[i]=char(s1[i]+(j>=?s2[j]-'':)); //注意细节 if(s1[i]-''>=) { s1[i]=char((s1[i]-'')%+''); if(i) s1[i-]++; else s1=''+s1; } } return s1; } int main()
{
int n;
while(~scanf("%d",&n))
{
string p[n+];
if(n<=)
{
printf("1\n");
continue;
}
p[]="";
p[]="";
p[]="";
p[]="";
for(int i=; i<=n; i++)
{
p[i]=add(p[i-],add(p[i-],add(p[i-],p[i-])));
}
cout<<p[n]<<endl;
}
return ;
}

HDU 1250 Hat's Fibonacci(大数相加)的更多相关文章

  1. HDOJ/HDU 1250 Hat's Fibonacci(大数~斐波拉契)

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

  2. hdu 1250 Hat's Fibonacci

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

  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(java,简单,大数)

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

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

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

  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&#39;s Fibonacci

    pid=1250">点击此处就可以传送hdu 1250 Problem Description A Fibonacci sequence is calculated by adding ...

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

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

  9. hdu 4099 Revenge of Fibonacci 大数+压位+trie

    最近手感有点差,所以做点水题来锻炼一下信心. 下周的南京区域赛估计就是我的退役赛了,bless all. Revenge of Fibonacci Time Limit: 10000/5000 MS ...

随机推荐

  1. 使用 typeof 来检测对象是否undefined

    需求 判断是否为undefined 解决 使用 typeof 来检测对象是否已定义: if (typeof Obj !== "undefined" && Obj ! ...

  2. 前端小结(5)---- iframe

    iframe对应的div: <div id="iframezone"> <iframe id="iframe" frameborder='0' ...

  3. shell编程之export

    shell 与 export命令用户登录到Linux系统后,系统将启动一个用户shell.在这个shell中,可以使用shell命令 或声明变量,也可以创建并运行shell脚本程序.运行shell脚本 ...

  4. Csharp: speech to text, text to speech in win

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  5. Csharp:WebClient and WebRequest use http download file

    //Csharp:WebClient and WebRequest use http download file //20140318 塗聚文收錄 string filePath = "20 ...

  6. 理解mouseover,mouseout,mouseenter,mouseleave

    mouseover定义和用法 当鼠标指针位于元素上方时,会发生 mouseover 事件. 该事件大多数时候会与 mouseout 事件一起使用. mouseover() 方法触发 mouseover ...

  7. ArcGIS DataStore手册——常见问题篇

    第三章:ArcGIS DataStore常见问题处理 1.DataStore使用的数据库是什么? 从安装后的内容和配置完DataStore中Server Manager中的信息来看,DataStore ...

  8. How to use DBVisualizer to connect to Hbase using Apache Phoenix

    How to use DBVisualizer to connect to Hbase using Apache Phoenix Article DB Visualizer is a popular ...

  9. Android Timer和TimerTask

    以下内容根据 The JavaTM Tutorial 和相关API doc翻译整理,以供日后参考: 1.概览 Timer是一种定时器工具,用来在一个后台线程计划执行指定任务.它可以计划执行一个任务一次 ...

  10. char和varchar的区别

    在建立数据库表结构的时候,为了给一个String类型的数据定义一个数据库的数据库类型,一般参考的都是char或者varchar,这两种选择有时候让人很纠结,今天想总结一下它们两者的区别,明确一下两者的 ...