日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HDU1250 Hat's Fibonacci 大数斐波那契数列

發(fā)布時間:2024/10/6 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU1250 Hat's Fibonacci 大数斐波那契数列 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

點擊打開鏈接

Hat's Fibonacci

Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12650????Accepted Submission(s): 4253


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 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???|???We have carefully selected several similar problems for you:??1753?1865?1715?1002?2100

解法:

題中要求的數最大可能到兩千多位,直接開二維數組會空間超限,
所以可以用a[ ][ ]存取一個四位,五位…或八位數等,減小數組的大小,
下面以五位數為例,每次算的結果由以前的對10取余改變成對10萬取余,
輸出的時候找到第一位不是0的輸出,以后的都按照%05d輸出


#include<stdio.h> #include<string.h> int a[10001][520]; void fun() {a[1][0]=1;a[2][0]=1;a[3][0]=1;a[4][0]=1;for(int i=5; i<10000; i++){int t=0;for(int j=0; j<=510; j++){a[i][j]=a[i-1][j]+a[i-2][j]+a[i-3][j]+a[i-4][j]+t;t=a[i][j]/100000;a[i][j]=a[i][j]%100000;}}} int main() {fun();int n;while(~scanf("%d",&n)){int i;for( i=510; a[n][i]==0; i--);printf("%d",a[n][i]);for(int j=i-1; j>=0; j--)printf("%05d",a[n][j]);printf("\n");}return 0; }

總結

以上是生活随笔為你收集整理的HDU1250 Hat's Fibonacci 大数斐波那契数列的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。