传送门: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. MyBatis 学习(一)

    一.MyBatis 1.MyBatis 介绍(百度) MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数 ...

  2. 决策树之ID3算法

    一.决策树之ID3算法简述 1976年-1986年,J.R.Quinlan给出ID3算法原型并进行了总结,确定了决策树学习的理论.这可以看做是决策树算法的起点.1993,Quinlan将ID3算法改进 ...

  3. AndroidVideoCache 框架源码分析

    1.简析: 在客户端播放视频的使用,容易出现这样的一个问题.在网络状况不好的情况下,视频流很容易卡顿或者中断,即使播放软件本身有一点的缓存能力,但是这个往往不够,造成播放失败,卡顿. AndroidV ...

  4. 小任务之Canvas绘制时钟

    背景图的绘制(大圆.数字.小圆点) 掌握基础知识:圆的绘制(arc方法),关于圆的弧度的计算,数学中关于sin cos的用法 圆的弧度为2*Math.PI 12个数字分得弧度每个为2*Math.PI/ ...

  5. Scrapy框架的使用

    Scrapy框架的安装 pip install pywin32 下载 Twisted 包       pip install Twisted包的路径 pip insatll scrapy Scrapy ...

  6. andriod导入v4包导致的错误

    最近升级android studio到版本3.0.1后,想要使用FragmentActivity这个类,导入v4包,发现R文件报错了,也就是找不到的意思. 如图:导包 此时选中v4包导进去. 确定之后 ...

  7. less @import and extend及mixin详解

    在less中,通过 @import (keyword) "filename"的方式引入其他的文件,这个keyword可以是以下6种: referrence referrence这个 ...

  8. 修改 Linux VM 中单个用户最大进程数的限制

    在部署有并发任务执行的虚机上, 会遇到 SSH 无法访问的问题. 本文将帮助你找出其中一种比较特殊的原因, 并提供解决方案. Note 以下案例分析基于 CentOS 7, 对于其他版本的 Linux ...

  9. C# FTP删除文件以及文件夹

    1.FTP文件操作类   FtpClient using System; using System.Collections.Generic; using System.Linq; using Syst ...

  10. 在Ubuntu16.04.4上安装docker

    在Ubuntu16.04.4上安装docker 一.环境准备     首先我们需要一台Ubuntu16.04 虚拟机或者真机,其次,我们对其进行环境配置.       1.1.移除已经安装过的dock ...