Hat's Fibonacci

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

 

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


Note:
No generated Fibonacci number in excess of digits will be in the test data, ie. F() = has digits.

问题大意与分析

就是一个变种的斐波那契,在处理大数相加的时候我用了string 被bug绊了好久...明天好好学学string

#include<bits/stdc++.h>

using namespace std;

int n,i;
string bigadd(string a,string b)
{
int jin=,i;
char ai,bi;
string anss=a;
int lena=a.size();
int lenb=b.size();
int lenmax=max(lena,lenb);
int p=lena-;
int q=lenb-;
for(i=lenmax-;i>=;i--)
{
if(p<)
ai='';
else
ai=a[p];
if(q<)
bi='';
else
bi=b[q];
anss[i]=((ai-''+bi-''+jin)%)+'';
jin=(ai-''+bi-''+jin)/;
p--;
q--;
}
if(jin)
{
char x=jin+'';
anss=x+anss;
}
return anss;
}
/*
int main()
{
while(scanf("%d",&n)!=EOF)
{
string a="1";
string b="1";
string c="1";
string d="1";
for(i=5;i<=n;i++)
{
string temp=d;
d=bigadd(bigadd(a,b),bigadd(c,d));
a=b;
b=c;
c=temp;
}
cout<<a <<b <<c <<d<<endl;
}
} */
int main(){
string a[]; //我之前用了4个string 出错了 好像是和长度有关
a[]="";
a[]="";
a[]="";
a[]="";
for(i=;i<;++i)
a[i]=bigadd(bigadd(bigadd(a[i-],a[i-]),a[i-]),a[i-]);
while(scanf("%d",&n)!=EOF)
{
cout<<a[n]<<endl;
}
return ;
}

HDU 1250 Hat's Fibonacci (递推、大数加法、string)的更多相关文章

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

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

  2. hdu 1250 Hat's Fibonacci

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

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

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

  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. POJ 2506 Tiling (递推 + 大数加法模拟 )

    Tiling Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7965   Accepted: 3866 Descriptio ...

  8. hdu 4099 Revenge of Fibonacci 字典树+大数

    将斐波那契的前100000个,每个的前40位都插入到字典树里(其他位数删掉),然后直接查询字典树就行. 此题坑点在于 1.字典树的深度不能太大,事实上,超过40在hdu就会MLE…… 2.若大数加法时 ...

  9. Children’s Queue HDU 1297 递推+大数

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1297 题目大意: 有n个同学, 站成一排, 要求 女生最少是两个站在一起, 问有多少种排列方式. 题 ...

随机推荐

  1. CNN简略总结

    https://blog.csdn.net/real_myth/article/details/51824193 池化层的作用: 感受野变化...?? 1*1卷积核的作用 1. 实现跨通道的交互和信息 ...

  2. 织梦dedecms做的网站首页标题篡改跳转赌博网站解决方案

    织梦dedecms因其强大功能,简单实用的优点常常被用来做企业网站,程序开源使用的人多了网站漏洞多会有中毒的情况,常见的有一种,首页标题关键词描述被篡改,百度快照收录点击后跳转的赌博网站,怎么解决这个 ...

  3. sql DATEDIFF函数使用

    date_part abbreviations year yy, yyyy quarter qq, q month mm, m dayofyear dy, y day dd, d week wk, w ...

  4. Springboot设置session超时时间

    按优先级高到低说: 第一种: spring boot 启动类里面: package com.mycenter; import org.mybatis.spring.annotation.MapperS ...

  5. qq在线咨询

    <a href="http://wpa.qq.com/msgrd?v=3&uin=2395848377&site=qq&menu=yes"> & ...

  6. iptables中DNAT和SNAT转发的配置方法

    1.一对一流量完全DNAT 首先说一下网络环境,普通主机一台做防火墙用,网卡两块 eth0 192.168.0.1  内网 eth1 202.202.202.1 外网 内网中一台主机 192.168. ...

  7. jenkins集成python的单元测试

    最近在研究jenkins的集成,然后想把自己写的python工具也用jenkins集成一下 废话少说,来看结构 sparking.py ''' @author: lianying ''' class ...

  8. 「HEOI 2016/TJOI 2016」求和

    题目链接 戳我 \(Solution\) 先化简式子: \[f(n)=\sum_{i=0}^n\sum_{j=0}^i\begin{Bmatrix} i \\ j \end {Bmatrix}*2^j ...

  9. 3.1 JAVA集合框架以及区别

    涉及的参考链接:https://www.runoob.com/java/java-collections.html,http://how2j.cn/k/collection/collection-ar ...

  10. HBuilder搭建Android模拟器

    HBuilder搭建Android模拟器  //来源:  https://www.cnblogs.com/bjxingch/articles/6657938.html  1.下载夜神Android模拟 ...