【Fibonacci】BestCoder #28B Fibonacci
Fibonacci
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 795 Accepted Submission(s): 213
Fi=
0, i = 0
1, i = 1
Fi−1+Fi−2, i > 1
Now we need to check whether a number can be expressed as the product of numbers in the Fibonacci sequence.(一开始没理解题意,其实我觉得这题意也不大好=。 =,题解说是Fib乘积,但和为什么不行呢,路过的可以帮忙解答一下)
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
4
17
233
No
Yes
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
const int maxn = ;
int f[maxn], tmp[maxn], j, k;
void Fibonacci()
{
f[] = ; f[] = ;
k = ;
while(f[k-] + f[k-] <= )
{
f[k] = f[k-] + f[k-];
k++;
}
}
bool Judge(int x, int step)//注意这里没有step的话会tle。。。
{
if(x == ) return true;
for(int i = step; i < j; i++)
{
if(x%tmp[i] == )
{
if(Judge(x/tmp[i], i))
return true;
}
}
return false;
}
int main()
{
Fibonacci();
int T;
scanf("%d", &T);
for(int i = ; i < T; i++)
{
int n;
scanf("%d", &n);
if(!n) printf("Yes\n");
else
{
j = ;
for(int i = ; i < k; i++)
{
if(n%f[i] == )
tmp[j++] = f[i];
}
if(Judge(n, )) printf("Yes\n");
else printf("No\n");
}
}
return ;
}
【Fibonacci】BestCoder #28B Fibonacci的更多相关文章
- 【CF914G】Sum the Fibonacci 快速??变换模板
[CF914G]Sum the Fibonacci 题解:给你一个长度为n的数组s.定义五元组(a,b,c,d,e)是合法的当且仅当: 1. $1\le a,b,c,d,e\le n$2. $(s_a ...
- 【hdoj_1250】Hat's Fibonacci(大数)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1250 思路:本题的Fibonacci数列是扩展的四阶的Fibonacci数列,用递推关系式求解即可. 题目 ...
- 【BZOJ2813】奇妙的Fibonacci
Description Fibonacci数列是这样一个数列: F1 = 1, F2 = 1, F3 = 2 . . . Fi = Fi-1 + Fi-2 (当 i >= 3) pty忽 ...
- 【bzoj2813】 奇妙的Fibonacci数列 线性筛
Description Fibonacci数列是这样一个数列: F1 = 1, F2 = 1, F3 = 2 . . . Fi = Fi-1 + Fi-2 (当 i >= 3) pty忽然对这个 ...
- 【BZOJ】1987: Zju2672 Fibonacci Subsequence
题意 给出一个序列\(A\),求一个最长的满足fib性质的子序列,输出其长度及其元素(如果多种方案,输出位置最靠前的).(\(n \le 3000\)) 题解 容易想到dp,即\(d(i, j)\)表 ...
- 【CF446C】DZY Loves Fibonacci Numbers (线段树 + 斐波那契数列)
Description 看题戳我 给你一个序列,要求支持区间加斐波那契数列和区间求和.\(~n \leq 3 \times 10 ^ 5, ~fib_1 = fib_2 = 1~\). Solut ...
- 【codeforces914G】Sum the Fibonacci FWT+FST(快速子集变换)
题目描述 给出一个长度为 $n$ 的序列 $\{s\}$ ,对于所有满足以下条件的五元组 $(a,b,c,d,e)$ : $1\le a,b,c,d,e\le n$ : $(s_a|s_b)\& ...
- 【二分】bestcoder p1m2
模型的转化和二分check的细节挺不错的 Problem Description 度度熊很喜欢数组!! 我们称一个整数数组为稳定的,若且唯若其同时符合以下两个条件: 数组里面的元素都是非负整数. 数组 ...
- 【HDU1848】Fibonacci again and again(博弈论)
[HDU1848]Fibonacci again and again(博弈论) 题面 Hdu 你有三堆石子,每堆石子的个数是\(n,m,p\),你每次可以从一堆石子中取走斐波那契数列中一个元素等数量的 ...
随机推荐
- WSGI和PASTE
WSGI就是一个标准,WSGI server就是实现了这个标准的一个容器.这个标准类似于如下的东东: 1 2 3 4 5 6 7 8 9 10 11 from wsgiref.simple_serve ...
- 【暑假】[实用数据结构]KMP
KMP算法 KMP算法是字符串匹配算法,可以在O(n)的时间完成,算法包含两部分,分别是:构造适配函数与两串匹配. 失配边的使用大大提高了算法效率,可以理解为已经成功匹配的字符不在重新匹配,因为我们已 ...
- 让你系统认识flume及安装和使用flume1.5传输数据到hadoop2.2
本文链接: http://www.aboutyun.com/thread-7949-1-1.html 问题导读:1.什么是flume?2.如何安装flume?3.flume的配置文件与其它软件有什么不 ...
- leetcode@ [22]Generate Parentheses (递归 + 卡特兰数)
https://leetcode.com/problems/generate-parentheses/ Given n pairs of parentheses, write a function t ...
- Mongodb 和 普通数据库 各种属性 和语句 的对应
SQL to MongoDB Mapping Chart In addition to the charts that follow, you might want to consider the F ...
- rabbitMQ 笔记
1. 端口 rabbitMQ server 使用的端口是5672 , AMQP协议的端口 rabbitMQ web 使用的端口是15672 , 管理工具的端口 rabbitMQ cl ...
- POJ3468--A Simple Problem with Integers(Splay Tree)
虽然有点难,但是这套题都挂了一个月了啊喂…… 网上模板好多……最后还是抄了kuangbin聚聚的,毕竟好多模板都是抄他的,比较习惯…… POJ 3468 题意:给n个数,两种操作,区间整体加一个数,或 ...
- hdoj 1262 寻找素数对
寻找素数对 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- IOS-- UIView中的坐标转换
// 将像素point由point所在视图转换到目标视图view中,返回在目标视图view中的像素值 - (CGPoint)convertPoint:(CGPoint)point toView:(UI ...
- webServices
引用项目的配置文件: <system.serviceModel> <bindings> <basicHttpBinding> <!--旅游供应--> & ...