hdu 1250 Hat's Fibonacci
来源:互联网 发布:freehand for mac 编辑:程序博客网 时间:2024/04/27 23:06
Hat's Fibonacci
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3726 Accepted Submission(s): 1252
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.
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
4203968145672990846840663646Note:No generated Fibonacci number in excess of 2005 digits will be in the test data, ie. F(20) = 66526 has 5 digits.
Author
戴帽子的
Recommend
Ignatius.L
这道题着实花了不少时间,倒不是花在解题思路上,而是花在了调试上面。总共提交了8次,算是最失败的了。
因为我是用打表,第一次,一个数组元素存一个十进制数,MLE。
换成了一个元素存5个十进制数,因为数组开大了点,又一次MLE。
而后两次run time error就特别怨了,也是在这花了超多是间,因为根本就看不到还有一个d%
另外需要注意的就是存五个数时,第一个需要特别处理。切记
View Code
Problem : 1250 ( Hat's Fibonacci ) Judge Status : Runtime Error
(ACCESS_VIOLATION)
RunId : 6290695 Language : C++ Author : NealGavin
Code Render Status : Rendered By HDOJ C++ Code Render Version 0.01 Beta
(ACCESS_VIOLATION)
RunId : 6290695 Language : C++ Author : NealGavin
Code Render Status : Rendered By HDOJ C++ Code Render Version 0.01 Beta
#include<cstring>#include<cstdio>#include<algorithm>using namespace std;const int MAX=800;int f[MAX][MAX];void goon(){ int d=0;//余数 for(int i=5;i<MAX;i++) { for(int j=1;j<=f[i-1][0];j++) { f[i][j]=f[i-1][j]+f[i-2][j]+f[i-3][j]+f[i-4][j]+d; d=f[i][j]/10; f[i][j]%=10; 就是这行在编译器里一直没发现哎痛苦 ——》 f[i][j]%=10; } f[i][0]=f[i-1][0]; while(d) { f[i][++f[i][0]]=d%10; d/=10; } }}int main(){ //freopen("2.out","w",stdout); memset(f,0,sizeof(f)); for(int i=1;i<5;i++) { f[i][0]=f[i][1]=1; } goon(); int m; while(scanf("%d",&m)!=EOF) { for(int i=f[m][0];i>0;i--) printf("%d",f[m][i]); printf("\n"); //printf("A%d\n",f[m][0]); }}
View Code
Problem : 1250 ( Hat's Fibonacci ) Judge Status : Wrong Answer
RunId : 6291203 Language : C++ Author : NealGavin
Code Render Status : Rendered By HDOJ C++ Code Render Version 0.01 Beta
RunId : 6291203 Language : C++ Author : NealGavin
Code Render Status : Rendered By HDOJ C++ Code Render Version 0.01 Beta
#include<cstring>#include<cstdio>#include<algorithm>using namespace std;const int MAX=8001;const int mod=100000;int f[MAX][600];void goon(){ int d=0;//余数 for(int i=5;i<MAX;i++) { for(int j=1;j<=f[i-1][0];j++) { f[i][j]+=f[i-1][j]+f[i-2][j]+f[i-3][j]+f[i-4][j]+d; if(f[i][j]>=mod) { d=f[i][j]/mod; f[i][j]%=mod; } else d=0; } f[i][0]=f[i-1][0]; while(d) { f[i][++f[i][0]]=d%mod; d/=mod; } }}int main(){ //freopen("2.out","w",stdout); memset(f,0,sizeof(f)); for(int i=1;i<5;i++) { f[i][0]=f[i][1]=1; } goon(); int m; while(scanf("%d",&m)!=EOF) { for(int i=f[m][0];i>0;i--) 就是这没处理,WA
printf("%05d",f[m][i]); printf("\n"); // printf("A%d\n",f[m][0]); }}
#include<cstring>#include<cstdio>#include<algorithm>using namespace std;const int MAX=8033;const int mod=100000;int f[MAX][800];void goon(){ int d=0;//进位 for(int i=5;i<MAX;i++) { for(int j=1;j<=f[i-1][0];j++) { f[i][j]=f[i-1][j]+f[i-2][j]+f[i-3][j]+f[i-4][j]+d; if(f[i][j]>=mod) { d=f[i][j]/mod; f[i][j]%=mod; } else d=0; } f[i][0]=f[i-1][0]; while(d) { f[i][++f[i][0]]=d%mod; d/=mod; } }}int main(){ //freopen("2.out","w",stdout); memset(f,0,sizeof(f)); for(int i=1;i<5;i++) { f[i][0]=f[i][1]=1; } goon(); int m; while(scanf("%d",&m)!=EOF) { printf("%d",f[m][f[m][0]]); for(int i=f[m][0]-1;i>0;i--) printf("%05d",f[m][i]); printf("\n"); // printf("A%d\n",f[m][0]); }}
- hdu 1250 Hat's Fibonacci
- HDU 1250 Hat's Fibonacci
- Hdu 1250 Hat's Fibonacci
- hdu 1250 Hat's Fibonacci
- HDU 1250-Hat's Fibonacci
- hdu 1250 Hat's Fibonacci
- hdu-1250-Hat's Fibonacci
- Hdu---Hat's Fibonacci---1250
- hdu 1250 Hat's Fibonacci
- hdu 1250 Hat's Fibonacci
- hdu 1250 Hat's Fibonacci
- hdu 1250 Hat's Fibonacci
- HDU 1250: Hat's Fibonacci
- hdu 1250 Hat's Fibonacci
- hdu 1250 Hat's Fibonacci
- hdu-1250-Hat's Fibonacci
- HDU 1250 Hat's Fibonacci
- HDU 1250 Hat's Fibonacci
- iOS 数据持久性存储--属性列表存储
- 怎么阅读代码
- 程序员(每天、每周、每月、每年)该做的事
- 暑期实训总结_杨立涛
- 做生意和打工的区别
- hdu 1250 Hat's Fibonacci
- 暑假实训的体会与感受_11-java-张玥
- dtree的使用和扩展
- 实训总结_靳晓发
- OpenNMS阀值、事件及警告配置笔记--开源监控软件
- 小技巧总结
- android:gravity 和android:layout_gravity的区别 android:padding和android:layout_margin的区别
- Delphi关于多线程同步的一些方法
- 列表