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. git常用命令及常见问题解析

    1.查看状态 1.git status 2.git status -a 2.初始化一个git仓库 git init git clone 'git仓库地址' 3.添加到暂存区 //目录 git add ...

  2. css-动画,a标签下,文字加下划线,而且动画是由中间向两边扩展开

    效果: html: <div class="warp"> <a class="welcome">期待您的参与</a> < ...

  3. Java多线程和并发(九),ReentrantLock(公平锁)

    目录 1.ReentrantLock 2.ReentrantLock的实现 3.synchronized和ReentrantLock的区别 九.ReentrantLock(公平锁) 1.Reentra ...

  4. cogs1619. [HEOI2012]采花 x

    1619. [HEOI2012]采花 ★★☆   输入文件:1flower.in   输出文件:1flower.out   简单对比时间限制:5 s   内存限制:128 MB [题目描述] 萧薰儿是 ...

  5. 大哥带的XSS练习

    0x01反射型 <script>alert("zhong")</script> 可以看见什么都没有过滤 0x02存储型XSS http://www.xss_ ...

  6. python学习之路(6)

    使用dict和set Python内置了字典:dict的支持,dict全称dictionary,在其他语言中也称为map,使用键-值(key-value)存储,具有极快的查找速度. 举个例子,假设要根 ...

  7. 前端学习之三——jquery选择器

    Jquery中的选择器分为几大类:基本过滤选择器,层次选择器,内容过滤选择器,可见性过滤选择器,属性过滤选择器,子元素过滤选择器,表单对象选择器和表单对象属相过滤选择器. 1.非基本过滤选择器,一般需 ...

  8. 小程序踩坑之获取不到e.target.dataset的值

    在页面与js传值中我们经常用到data-id="1"的方式,然后通过e.target.dataset.id取id的值今天在获取值时怎么也取不到,后来发现e对象有currentTar ...

  9. DS博客作业08—课程总结

    1.当初你是如何做出选择计算机专业的决定的? 开始时我选择的专业就是网络/物联网,计算机专业是一个充满创造性的专业 2.对比开篇博客,哪些方面还存在哪些不足? 这个人就像戏台上的老将军,全身插满fla ...

  10. Python中Counter统计数据输出具体办法

    from collections import Counter # 列表 l_one = [1709020621, 1709020621, 1770603107, 1770603105, 177060 ...