HDU 5167(map + 暴力)
2016-05-12 20:55
295 查看
题意:给出一个数n,问n能否是斐波那契数列中数的乘积
先刷选 斐波那契数列,然后就枚举
View Code
先刷选 斐波那契数列,然后就枚举
#include <cstdio> #include <cstring> #include <queue> #include <map> #include <iostream> using namespace std; typedef long long LL; const LL Max = 1000000000; LL num[50]; map<LL, bool> m; void init() { queue<LL> q; m[0] = true; m[1] = true; num[0] = 0; num[1] = 1; for (int i = 2; i < 46; i++) { num[i] = num[i - 1] + num[i - 2]; q.push(num[i]); m[ num[i] ] = true; } while (!q.empty()) { int temp = q.front(); q.pop(); for (int i = 1; i < 46; i++) { LL res = temp * num[i]; if (res > Max) break; if (m[ res ]) continue; m[ res ] = true; q.push(res); } } } int main() { init(); int test, n; scanf("%d", &test); while (test--) { scanf("%d", &n); if (m[ n ]) printf("Yes\n"); else printf("No\n"); } return 0; }
View Code
相关文章推荐
- sprint
- Ubuntu下automake工具的使用
- CentOS硬软链接
- 模拟猜数(POJ2328)
- 生成1-n的排列
- zoj水题分类(自己练习)
- awk 参考
- 三种方法遍历ArrayList
- 启动hive报错:[ERROR] Terminal initialization failed; falling back to unsupported
- JAVA编写简单的http服务器
- sql中的行转列和列转行的问题
- SNF微信公众号客户端演示-微信开发客户端能干什么
- 斜率优化dp专题学习
- 亿级用户下的新浪微博平台架构
- 鸡兔同笼
- 排列组合问题
- 蓝桥杯 车票找零
- 【Objective-C】OC中键值编码(KVC)的概念和使用方法
- POJ 3061 - Subsequence
- 安卓之窗口机制初涉(一)