zoukankan      html  css  js  c++  java
  • 杭电 Problem 1715 大菲波数

    大菲波数

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 17183    Accepted Submission(s): 5708


    Problem Description
    Fibonacci数列,定义如下:
    f(1)=f(2)=1
    f(n)=f(n-1)+f(n-2) n>=3。
    计算第n项Fibonacci数值。
     

    Input
    输入第一行为一个整数N,接下来N行为整数Pi(1<=Pi<=1000)。
     

    Output
    输出为N行,每行为对应的f(Pi)。
     

    Sample Input
    5 1 2 3 4 5
     

    Sample Output
    1 1 2 3 5
     

    Source

    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <queue>
    #include <stack>
    #include <iostream>
    #define MAX_N   1005
    #define MAX(a, b) (a > b)? a: b
    #define MIN(a, b) (a < b)? a: b
    using namespace std;
    
    int fib[MAX_N][MAX_N];
    void init() {
        fib[1][0] = 1, fib [2][0] = 1;
        for (int i = 3; i < 1001; i++) {
            int p = 0, q = 0;
            for (int j = 0; j < 550; j++) {
                p = fib[i - 1][j] + fib[i - 2][j] + q;
                fib[i][j] = p%10;
                q = p/10;
            }
        }
    }
    
    int main() {
        int t, n, i;
        init();
        scanf("%d", &t);
        while (t--) {
            scanf("%d", &n);
            for (i = 550; i >= 0; i--) {
                if (fib[n][i] != 0) break;
            }
            for (; i >= 0; i--) {
                printf("%d", fib[n][i]);
            }
            printf("
    ");
        }
        return 0;
    }
    


  • 相关阅读:
    Windows 8.1 序列化与反序列化
    window store app 附件读取
    Window 8.1 计时器功能及图片切换
    c#多层嵌套Json
    isNotNull与isNotEmpty的区别
    商务用语
    国家气象局三天天气WebService接口
    WebServise
    EF架构基础代码
    接口定义
  • 原文地址:https://www.cnblogs.com/cniwoq/p/6770941.html
Copyright © 2011-2022 走看看