您的位置:首页 > 其它

hdu 5167 Fibonacci 打表

2016-10-27 19:38 281 查看

Fibonacci

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


[align=left]Problem Description[/align]
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.

[align=left]Input[/align]
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

[align=left]Output[/align]
For each case output "Yes" or "No".

[align=left]Sample Input[/align]

3
4
17
233

[align=left]Sample Output[/align]

Yes
No
Yes

[align=left]Source[/align]
BestCoder Round #28
题意:问一个数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
;
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
)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: