The Fibonacci numbers (0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ...) are defined by the recurrence:
????? F0 = 0
將下列ieee短浮點數轉換為十進制數、????? F1 = 1
????? Fi = Fi?1 + Fi?2 for all i ≥ 2
? Write a program to calculate the Fibonacci Numbers.
9999二進制有多少個1?Input
The input to your program would be a sequence of numbers smaller or equal than 5000, each on a separate line, specifying which Fibonacci number to calculate.
Output
十六進制和二進制哪個大?Your program should output the Fibonacci number for each input value, one per line.
Sample Input
5
哪個進制數最大。7
11
Sample Output
十進制大還是二進制大。The Fibonacci number for 5 is 5
The Fibonacci number for 7 is 13
The Fibonacci number for 11 is 89
問題鏈接:UVA495 Fibonacci Freeze
問題簡述:(略)
問題分析:
? 大數計算問題。
程序說明:
? 用二維數組來表示大數,并且采用萬進制,高位在每一行的右邊(低位在左邊)。
? 其他都是套路。
題記:(略)
參考鏈接:(略)
AC的C++語言程序如下:
/* UVA495 Fibonacci Freeze */#include <bits/stdc++.h>using namespace std;const int N = 5000;
const int N2 = 300;
const int BASE = 1e4;
int fib[N+ 1][N2 + 1];void maketable()
{memset(fib, 0, sizeof(fib));fib[0][0] = 0;fib[1][0] = 1;for ( int i = 2 ; i <= N ; i++ ) {for ( int j = 0 ; j <= N2 ; j++ )fib[i][j] = fib[i-2][j] + fib[i-1][j];for ( int j = 0 ; j <= N2 ; j++ ) {fib[i][j+1] += fib[i][j] / BASE;fib[i][j] %= BASE;}}
}int main()
{maketable();int n;while(~scanf("%d", &n)) {int i = N2;while ( i >= 1 && !fib[n][i] )i --;printf("The Fibonacci number for %d is ", n);printf("%d", fib[n][i--]);while ( i >= 0 )printf("%04d", fib[n][i--]);printf("\n");}return 0;
}
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态