The Oculus【自然溢出】-2020杭电多校2

题意:

定义斐波那契数列:(F_1=1,F_2=2,...,F_n=F_{n-1}+F_{n-2})
任意一个数都可以表示成若干个斐波那契数之和,给出 (A)(B) 的斐波那契数表示和二者乘积的斐波那契数表示,并将乘积的表示中的一个 (1) 改成 (0),求出修改了哪一个位置。
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6768

分析:

代码:

#include <bits/stdc++.h>

using namespace std;
typedef unsigned long long ull;
const int N=2e6+6;
const int maxn=2e6;
ull f[N];
void init()
{
    f[1]=1;
    f[2]=2;
    for(int i=3;i<=maxn;i++)//自然溢出充当哈希
        f[i]=f[i-1]+f[i-2];
}
ull solve()
{
    ull res=0;
    int n,x;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&x);
        if(x==1) res+=f[i];
    }
    return res;
}
int main()
{
    int t;
    init();
    scanf("%d",&t);
    ull a,b,c;
    while(t--)
    {
        a=solve();
        b=solve();
        c=solve();
        ull r=a*b-c,ans=0;
        for(int i=1;i<=maxn;i++)
        {
            if(r==f[i])
            {
                ans=i;
                break;
            }
        }
        printf("%llu
",ans);
    }
    return 0;
}

原文地址:https://www.cnblogs.com/1024-xzx/p/13416697.html