传送门: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. DataTables获取指定元素的行数据

    法1: 用jquey获取,var row = $('.edit').parent().parent(); 缺点:只能获取dom上的东西,不能获取没有渲染的数据 法2: 首先绑定行号到元素上 $('#e ...

  2. Failed to create the part's controls解决方法

    今早打开eclipse,所有的文件均打不开,如下所示: 因为项目从tomcat迁移到weblogic,JDK版本从1.8降到了1.6,EL表达式有些也解析不了,猜想是这其中出现了问题. 解决方法: F ...

  3. MARS3.6 Programming

    An Assembly Language I.D.E. To Engage Students Of All Levels * A Tutorial *2007 CCSC: Central Plains ...

  4. windows 下进程与线程的遍历

    原文:http://www.cnblogs.com/Apersia/p/6579376.html 在Windows下进程与线程的遍历有好几种方法. 进程与线程的遍历可以使用<TlHelp.h&g ...

  5. c# 控制台输出txt文件

    string tempFileName = "DETAIL_" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + ...

  6. python 路径练习

    目标: 编写一个程序,能在当前目录以及当前目录的所有子目录下查找文件名包含指定字符串的文件,并打印出相对路径. 代码: import os txt_list = [] # 获取的list def fi ...

  7. 关于WEB-INF目录下无法访问webapp下的css等静态文件

    第一种方法: <!-- 输出为项目根目录,即webapp--> <c:set value="${pageContext.request.contextPath}" ...

  8. C#中的多线程 - 同步基础 z

    原文:http://www.albahari.com/threading/part2.aspx 专题:C#中的多线程 1同步概要Permalink 在第 1 部分:基础知识中,我们描述了如何在线程上启 ...

  9. QA-IDEA中用maven配置项目无法加载JDBC

    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver Im building Maven Java Web application and w ...

  10. python 函数&条件,循环

    条件if <条件判断1>: <执行1>elif <条件判断2>: <执行2>elif <条件判断3>: <执行3>else: & ...