• 10.25 斐波那契


    思路:

    对于两个点,从fib数列的后面开始减,一直减的相等

    //std 80, 一堆bug
    
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    #include <cstring>
    #include <string>
    
    using namespace std;
    const int N = 95;
    
    #define LL long long
    
    LL f[N];
    LL m;
    
    inline LL read()
    {
        LL x = 0; char c = getchar();
        while(c < '0' || c > '9') c = getchar();
        while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
        return x;
    }
    
    int main()
    {
        freopen("fibonacci.in", "r", stdin);
        freopen("fibonacci.out", "w", stdout);
        f[1] = 1;
        f[2] = 1;
        for(int i = 3; i <= 90; i ++)
            f[i] = f[i - 1] + f[i - 2];
        m = read();
        for(int i = 1; i <= m; i ++)
        {
            LL a = read();
            LL b = read();
            if(a < b) swap(a, b);//baozheng a > b;
            bool flag = 1;
            int js = 90;
            while(a != b)
            {
                if(a > f[js]) a -= f[js];
                if(b > f[js]) b -= f[js];
                js --;
            }
            printf("%I64d
    ", a);
        } 
        
        return 0;
    }
    /*
    5
    1 1
    2 3
    5 7
    7 13
    4 12
    */
  • 相关阅读:
    git log中文乱码问题
    局域网映射公网IP
    Android Studio 的一些配置
    Android Studio的安装
    adb的安装
    python的安装
    CentOS 7 上部署 java web 项目
    SQL——SQL语句总结(8)
    SQL——SQL语句总结(7)
    SQL——SQL语句总结(6)
  • 原文地址:https://www.cnblogs.com/lyqlyq/p/7728774.html
Copyright © 2020-2023  润新知