zoukankan      html  css  js  c++  java
  • hdu 5167 Fibonacci 打表

    Fibonacci

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)


    Problem Description
    Following is the recursive definition of Fibonacci sequence:
    Fi=⎧⎩⎨01Fi1+Fi2i = 0i = 1i > 1

    Now we need to check whether a number can be expressed as the product of numbers in the Fibonacci sequence.
     
    Input
    There is a number T shows there are T test cases below. (T100,000)
    For each test case , the first line contains a integers n , which means the number need to be checked. 
    0n1,000,000,000
     
    Output
    For each case output "Yes" or "No".
     
    Sample Input
    3 4 17 233
     
    Sample Output
    Yes No Yes
     
    Source
    题意:问一个数n,能否由斐波那契数列中的某些数乘积组成;
    思路:打表,能组成的全弄出来;
    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define pi (4*atan(1.0))
    #define eps 1e-14
    const int N=2e5+10,M=4e6+10,inf=1e9+10,mod=1e9+7;
    const ll INF=1e18+10;
    map<ll,int>m;
    ll f[N];
    priority_queue<ll,vector<ll>,greater<ll> >q;
    void init()
    {
        int pre=0;
        int now=1;
        f[0]=0;
        f[1]=1;
        for(int i=2;i<=44;i++)
            f[i]=f[i-1]+f[i-2];
        for(int i=0;i<=44;i++)
            if(!m[f[i]])
            q.push(f[i]),m[f[i]]=1;
        while(!q.empty())
        {
            ll v=q.top();
            q.pop();
            for(int i=1;i<=44;i++)
            {
                if(f[i]*v<inf&&!m[f[i]*v])
                {
                    m[f[i]*v]=1;
                    q.push(f[i]*v);
                }
            }
        }
    }
    int main()
    {
        init();
        int T;
        scanf("%d",&T);
        while(T--)
        {
            int n;
            scanf("%d",&n);
            if(m[n])
                printf("Yes
    ");
            else
                printf("No
    ");
        }
        return 0;
    }
  • 相关阅读:
    进程Queue
    进程ID
    多进程
    queue 生产者、清费者
    让静态页面显示用户登录状态
    apache2.2 + tomcat6 整合以及集群配置整理
    linux安装rzsz
    http_load
    用Ant实现Java项目的自动构建和部署
    Openfire:安装指南
  • 原文地址:https://www.cnblogs.com/jhz033/p/6005228.html
Copyright © 2011-2022 走看看