• hdu 5167 Fibonacci(预处理)


    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
     
     
     
    题意:判断一个数能否由任意个菲波那媞数相乘得到,能的话输出“Yes”,否则输出“No”
    思路:首先要处理菲波那媞数组,然后用一个队列来实现菲波那媞数的相乘,用一个map数组来标记。具体看代码
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<stdlib.h>
     6 #include<algorithm>
     7 #include<queue>
     8 #include<map>
     9 using namespace std;
    10 #define N 46
    11 #define ll long long
    12 ll f[N];
    13 map<ll,bool>mp;
    14 void init()
    15 {
    16     mp.clear();
    17     queue<ll>q;
    18     f[0]=0;
    19     f[1]=1;
    20     mp[0]=true;
    21     mp[1]=true;
    22     q.push(0);
    23     q.push(1);
    24     for(int i=2;i<N;i++)
    25     {
    26         f[i]=f[i-1]+f[i-2];
    27         mp[f[i]]=true;
    28         q.push(f[i]);
    29     }
    30     while(!q.empty())
    31     {
    32         ll tmp=q.front();
    33         q.pop();
    34         for(int i=0;i<N;i++)
    35         {
    36             ll cnt=tmp*f[i];
    37             if(cnt>1000000000L)
    38               break;
    39             if(mp[cnt]) continue;
    40             mp[cnt]=true;
    41             q.push(cnt);
    42         }
    43     }
    44     
    45 }
    46 int main()
    47 {
    48     init();
    49     int t;
    50     scanf("%d",&t);
    51     while(t--)
    52     {
    53         ll n;
    54         scanf("%I64d",&n);
    55         if(mp[n]==true)
    56           printf("Yes
    ");
    57         else 
    58           printf("No
    ");
    59         
    60     }
    61     return 0;
    62 }
    View Code
  • 相关阅读:
    pzrNB!!!
    biu biu biu
    大笑三声再往下看!
    Selenium之Chrome浏览器的启动
    Selenium IDE脚本录制步骤简介
    Selenium IDE的一些操作
    Selenium IDE编辑区域修改操作学习
    在firefox安装Selenium IDE
    执行Java脚本firefox启动成功,不运行test方法,且提示NullPointerException
    Selenium+Python学习之一
  • 原文地址:https://www.cnblogs.com/UniqueColor/p/4743704.html
Copyright © 2020-2023  润新知