• zstuoj 4245 KI的斐波那契



    KI的斐波那契

    Time Limit: 1 Sec  Memory Limit: 128 MB
    Submit: 550  Solved: 208

    Description

    KI十分喜欢美丽而优雅的斐波那契数列,最近他新认识了一种斐波那契字符串,定义如下

    f (0) = b, f (1) = a,

    f (2) = f (1) + f (0) = ab,

    f (3) = f (2) + f (1) = aba,

    f (4) = f (3) + f (2) = abaab,

    ......

    KI想知道 f (n) 中的第 m 位是什么,你可以帮他解决这个问题吗?

    Input

    第一行有一个整数 T ,表示测试组数。

    接下来的每个测试组包含两个数 n, m

    数据范围: T 1000, 0 n 90, 1 m 1e18

    Output

    对于每个测试组,输出’a’或者’b’

    Sample Input

    54 15 310 2222 23366 2333333333333

    Sample Output

    aaaba
    #include <iostream>
    #include <cstdio>
    #include <queue>
    #include <cstring>
    #include <stack>
    #include <algorithm>
    typedef long long ll;
    using namespace std;
    const int N=100;
    ll f[N];
    void fi()
    {
        f[0]=1;
        f[1]=1;
        for(int i=2; i<=90; i++)
        {
            f[i]=f[i-1]+f[i-2];
        }
    }
    int f1(ll n,ll m)
    {
        if(n==1) return 1;
        if(n==2) return m==1?1:0;
        if(m>f[n-1]) return f1(n-2,m-f[n-1]);
        else return f1(n-1,m);
    
    }
    int main()
    {
        int t;
        scanf("%d",&t);
        fi();
        while(t--)
        {
            ll n,m;
            scanf("%lld %lld",&n,&m);
            f1(n,m)?puts("a"):puts("b");
        }
        return 0;
    }
    

  • 相关阅读:
    令人恼怒!mount windows共享目录出错
    今天修改PCB板图
    在深圳出差
    触摸屏技术原理介绍
    getrlimit和setrlimit函数
    OpenCV下的HelloWorld
    两本OpenCV的书到了
    GDB用法小结
    没搞懂自适应二进制阈值化的参数
    【JavaScript】73 逆序的三位数 (10分)
  • 原文地址:https://www.cnblogs.com/nyist-xsk/p/7264898.html
Copyright © 2020-2023  润新知