算法:搜索;

In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation

Fn = Fn-1 + Fn-2

with seed values F1 = 1; F2 = 1 (sequence A000045 in OEIS).

---Wikipedia



Today, Fibonacci takes revenge on you. Now the first two elements of Fibonacci sequence has been redefined as A and B. You have to check if C is in the new Fibonacci sequence.





Input

The first line contains a single integer T, indicating the number of test cases.



Each test case only contains three integers A, B and C.



[Technical Specification]

1. 1 <= T <= 100

2. 1 <= A, B, C <= 1 000 000 000





Output

For each test case, output “Yes” if C is in the new Fibonacci sequence, otherwise “No”.





Sample Input

3

2 3 5

2 3 6

2 2 110





Sample Output

Yes

No

Yes

代码:

#include <iostream>
#include <string>
#include <iomanip>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stdio.h>
using namespace std;
long long n,m,k;
long long s;
long long dfs(long long x,long long y)
{
s=x+y;
if(s==k) return 1;
if(x==k) return 1;
if(y==k) return 1;
if(s>k&&k!=x&&k!=y) return 0;
dfs(y,s);
}
int main()
{
int t;
cin>>t;
while(t--)
{ cin>>n>>m>>k;
int ans=dfs(n,m);
if(ans) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}

Revenge of Fibonacc的更多相关文章

  1. HDU 3341 Lost's revenge(AC自动机+DP)

    Lost's revenge Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)T ...

  2. HDU 5019 Revenge of GCD(数学)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5019 Problem Description In mathematics, the greatest ...

  3. L - Abbott's Revenge(比较复杂的bfs)

    Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UV ...

  4. hdu 4099 Revenge of Fibonacci 大数+压位+trie

    最近手感有点差,所以做点水题来锻炼一下信心. 下周的南京区域赛估计就是我的退役赛了,bless all. Revenge of Fibonacci Time Limit: 10000/5000 MS ...

  5. HDU5088——Revenge of Nim II(高斯消元&矩阵的秩)(BestCoder Round #16)

    Revenge of Nim II Problem DescriptionNim is a mathematical game of strategy in which two players tak ...

  6. HDU5087——Revenge of LIS II(BestCoder Round #16)

    Revenge of LIS II Problem DescriptionIn computer science, the longest increasing subsequence problem ...

  7. HDU5086——Revenge of Segment Tree(BestCoder Round #16)

    Revenge of Segment Tree Problem DescriptionIn computer science, a segment tree is a tree data struct ...

  8. UVA 816 - Abbott&#39;s Revenge(BFS)

    UVA 816 - Abbott's Revenge option=com_onlinejudge&Itemid=8&page=show_problem&category=59 ...

  9. hdu 4099 Revenge of Fibonacci Trie树与模拟数位加法

    Revenge of Fibonacci 题意:给定fibonacci数列的前100000项的前n位(n<=40);问你这是fibonacci数列第几项的前缀?如若不在前100000项范围内,输 ...

随机推荐

  1. CGlib使用案例

    实际对象: public class RealObject { public void doSomething() { System.out.println("RealObject.doSo ...

  2. RUBY,玩玩~~~

    我觉得吧,这东瀛的红宝石,也得玩玩,毕竟,RUBY ON RAILS,PUPPET等也是一股力量. 作为混IT圈的,知道总没坏处. 就是感觉和C,C++,JAVA,C#,PHP,甚至PYTHON的感觉 ...

  3. 在Qt中将函数发送到主线程执行

    考虑这样一种需求,使用Qt的线程类QThread在后台执行操作(比如说拷贝文件)的时候发生了错误,产生了一个错误信息需要提醒给用户,在后台输出很显然是不够的,因为用户可能根据就没有任何控制台可供程序输 ...

  4. Delphi新语法

    http://www.cnblogs.com/hnxxcxg/category/456344.html

  5. 【HDOJ】1506 Largest Rectangle in a Histogram

    Twitter还是Amazon拿这个题目当过面试题.DP区间求面积. /* 1506 */ #include <cstdio> #include <cstring> #incl ...

  6. 动态规划初级练习(一):ZigZag

    Problem Statement      A sequence of numbers is called a zig-zag sequence if the differences between ...

  7. Forward Proxy & Reverse Proxy | 正向代理 和 反向代理

    对请求和响应内容不做修改的转发的服务器,被称为代理服务器.代理服务器分为两种类型:正向代理 和 反向代理. 正向代理:面向互联网,从更广范围获取信息的代理. 反向代理:面向内部,一般用于某企业的网站的 ...

  8. 无需转化直接使用ESD映像文件安装系统简明教程

    原版系统ISO镜像的sources文件夹中包含install.wim映像文件,将这个WIM文件“解压”(官方术语“Apply”)后,可以看到和C盘的目录完全相同,即为系统文件. 而官方提供的原版ESD ...

  9. JQuery的ready函数与JS的onload的区别详解

    JQuery的ready函数与JS的onload的区别:1.执行时间window.onload必须等到页面内包括图片的所有元素加载完毕后才能执行.$(document).ready()是DOM结构绘制 ...

  10. php-redis扩展模块安装记录

    redis的安装可以参考:centos下部署redis服务环境的操作记录 下面记录下php-redis扩展模块的安装过程:php的安装目录是/Data/app/php5.6.26 下载phpredis ...