將下列ieee短浮點數轉換為十進制數,UVA495 Fibonacci Freeze【大數+萬進制】

 2023-11-18 阅读 19 评论 0

摘要: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

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;
}






版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/4/175950.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息