HDU 1250 Hat's Fibonacci (递推、大数加法、string)
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
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
Output
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)的更多相关文章
- HDU 1250 Hat's Fibonacci(大数相加)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1250 Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Ot ...
- hdu 1250 Hat's Fibonacci
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1250 Hat's Fibonacci Description A Fibonacci sequence ...
- HDOJ/HDU 1250 Hat's Fibonacci(大数~斐波拉契)
Problem Description A Fibonacci sequence is calculated by adding the previous two members the sequen ...
- hdu 1250 Hat's Fibonacci(java,简单,大数)
题目 java做大数的题,真的是神器,来一道,秒一道~~~ import java.io.*; import java.util.*; import java.math.*; public class ...
- hdu 1250 Hat's Fibonacci(高精度数)
// 继续大数,哎.. Problem Description A Fibonacci sequence is calculated by adding the previous two membe ...
- HDU 1250 Hat's Fibonacci(高精度)
Problem Description A Fibonacci sequence is calculated by adding the previous two members the sequen ...
- POJ 2506 Tiling (递推 + 大数加法模拟 )
Tiling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7965 Accepted: 3866 Descriptio ...
- hdu 4099 Revenge of Fibonacci 字典树+大数
将斐波那契的前100000个,每个的前40位都插入到字典树里(其他位数删掉),然后直接查询字典树就行. 此题坑点在于 1.字典树的深度不能太大,事实上,超过40在hdu就会MLE…… 2.若大数加法时 ...
- Children’s Queue HDU 1297 递推+大数
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1297 题目大意: 有n个同学, 站成一排, 要求 女生最少是两个站在一起, 问有多少种排列方式. 题 ...
随机推荐
- ubuntu安装wireshark
$sudo apt-add-repository ppa:wireshark-dev/stable$sudo apt update$sudo apt install wireshark 出于安全方面的 ...
- 【leetcode】1252. Cells with Odd Values in a Matrix
题目如下: Given n and m which are the dimensions of a matrix initialized by zeros and given an array ind ...
- mysql ef vs
https://www.cnblogs.com/dux2013/archive/2017/12/11/8025077.html
- Anaconda 安装+使用+换源+更新
anaconda官网下载安装:https://www.continuum.io/downloads/ anaconda用法:查看已经安装的包:pip list 或者 conda list 安装和更新: ...
- File类、FileInfo类、Directory类、DirectoryInfo类
File类.Directory类,都是静态类,可以直接使用类名 FileInfo类.DirectoryInfo类,都是动态类,需要new对象,通过对象来操作 [文件的创建.复制.移动.删除]using ...
- jquery disabled选择器 语法
jquery disabled选择器 语法 作用:disabled 选择器选取所有禁用的表单元素.大理石平台价格表 语法:$(":disabled") jquery disable ...
- Ubuntu镜像的MD5校验
造冰箱的大熊猫@cnblogs 2018/9/7 1.在Ubuntu终端中,按照以下格式输入命令计算镜像文件ubuntu-xxx.iso的MD5校验和. md5sum ubuntu-xxx.iso 2 ...
- lcez校内模拟赛: 小R与苹果派——题解
题目传送 首先对两个数组排序. 然后预处理出数组p[i]表示b[x]<a[i]的最大的x. 然后我们设f[i][k]表示对于前i个派,我单独选出来k组a[y]>b[y].(即此时有k组a& ...
- Android 一般动画animation和属性动画animator
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...
- Arrays类与Collections类
java.util.Arrays类包含一个静态的工厂,允许数组被视为列表.以下是关于数组的要点: 这个类包含了各种方法来操作数组(比如排序和搜索). 在这个类中的方法抛出NullPointerExce ...