Problem Description
Following is the recursive definition of Fibonacci sequence:

Fi=⎧⎩⎨01Fi−1+Fi−2i = 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. (T≤100,000) For each test case , the first line contains a integers n , which means the number need to be checked.  0≤n≤1,000,000,000
Output
For each case output "Yes" or "No".
Sample Input
3 4 17 233
Sample Output
Yes No Yes
Source
BestCoder Round #28
题意:判断一个数能否由任意个菲波那媞数相乘得到,能的话输出“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\n");
57         else
58           printf("No\n");
59
60     }
61     return 0;
62 }

View Code

转载于:https://www.cnblogs.com/UniqueColor/p/4743704.html

hdu 5167 Fibonacci(预处理)相关推荐

  1. 斐波那契数列大数的压位c语言,HDU 1568 Fibonacci(大数前4位)

    分析:x=1234567.求其前四位数: log10(x)=log10(1.234567)+6. 所以1.234567=10^(log10(x)-6). 1234 =(int) 10^(log10(x ...

  2. HDU 1568 Fibonacci【求斐波那契数的前4位/递推式】

    Fibonacci Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Proble ...

  3. hdu 1568 Fibonacci(fibonacci通项+对数性质)

    Fibonacci Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  4. 题解——HDU 1848 Fibonacci again and again

    一道组合游戏的题目 SG函数的板子题 预处理出SG函数的值然后回答询问即可 代码 #include <cstdio> #include <algorithm> #include ...

  5. HDU 1848 Fibonacci again and again(博弈)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1848 题意:游戏规则如下: 1.  这是一个二人游戏; 2.  一共有3堆石子,数量分别是m, n, ...

  6. HDU 1568 Fibonacci

    题目链接 Problem Description 2007年到来了.经过2006年一年的修炼,数学神童zouyu终于把0到100000000的Fibonacci数列(f[0]=0,f[1]=1;f[i ...

  7. HDU - 3533 Escape(预处理+A*)

    题目链接:点击查看 题目大意:题意我感觉描述的很不清楚..是看网上其他大佬的博客总结来的,大意就是我们要从点(0,0)走到点(n,m),然后在一些地方设置了炮塔(炮塔视为墙),可以向一个方向周期性地发 ...

  8. HDU 6755 Fibonacci Sum(二次剩余 + 二项式展开)

    Fibonacci Sum 斐波那契通项有an=15((1+52)n−(1−52)n)(15)k∑i=0n((1+52)ic−(1−52)ic)kA=1+52,B=1−52(15)k∑i=0n∑j=0 ...

  9. HDU 1568 Fibonacci ★(取科学计数法)

    题目大意:问fibonacci数列的第n项的前四个数.   很好的一道题~~~如果取后几位的话,取模就可以了,但取前几位显然没这么简单= =-- 但假如我们能把它表示成小数(科学计数法)的话,那么要取 ...

最新文章

  1. glog 报错解决: /bin/bash: aclocal-1.14: command not found
  2. 赠票 | 互联网大厂的数据治理与资产管理实战 | DAMS 2020
  3. MFC接收ShellExecute多个参数
  4. MyBaties异常之 ORA-00918: 未明确定义列
  5. iOS-----------关于组件化
  6. UINavigationController的简单使用
  7. linux十字符木马,Linux系统随机10字符病毒的清除
  8. 特朗普社交应用登苹果App Store下载量榜首
  9. Lua中local变量和非local变量的区别
  10. Treo 650使用专题及开发计划等
  11. VAssistX 常用快捷键
  12. 金蝶k3服务器的操作系统,金蝶k3服务器配置工具
  13. 内网html预览word,C# 实现Office在线预览
  14. python实现整数反转
  15. java全能速查宝典_MATLAB函数全能速查宝典 邓薇等 编著.pdf
  16. 除了汽车,自动驾驶还将颠覆这33个行业……
  17. Rust学习教程30 - Panic原理剖析
  18. Hadoop初入门的坑
  19. Unity UGUI 边缘泛光 描边 的简单实现
  20. Battery_MSCCC:基于MATLAB/Simulink的具有多级(5级)恒流控制的电池充放电仿真模型

热门文章

  1. 在Windows系统安装Nodejs
  2. 汇编 div_Solidity汇编开发简明教程
  3. date样式找不到_涡轮+国VI排放,顶配售价不到12万,家用轿车看它准没错
  4. python2和python3关系_升级python2至python3解决依赖关系
  5. 计算机的键盘功能,电脑键盘功能
  6. git只提交一张图片_Git 图形化操作之合并提交记录
  7. plsql job执行多个存储过程_spring-boot-micro-job一款分布式任务调度执行框架
  8. java 前端页面传过来的值怎么防止篡改_反爬虫,到底是怎么回事儿?
  9. elasticsearch 常用命令
  10. 26岁,发25篇SCI,当上211教授、博导。