您的位置:首页 > 其它

HDU 5167(map + 暴力)

2016-05-12 20:55 295 查看
题意:给出一个数n,问n能否是斐波那契数列中数的乘积

先刷选 斐波那契数列,然后就枚举

#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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: