Revenge of Fibonacc
算法:搜索;
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的更多相关文章
- 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 ...
- HDU 5019 Revenge of GCD(数学)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5019 Problem Description In mathematics, the greatest ...
- L - Abbott's Revenge(比较复杂的bfs)
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Practice UV ...
- hdu 4099 Revenge of Fibonacci 大数+压位+trie
最近手感有点差,所以做点水题来锻炼一下信心. 下周的南京区域赛估计就是我的退役赛了,bless all. Revenge of Fibonacci Time Limit: 10000/5000 MS ...
- 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 ...
- HDU5087——Revenge of LIS II(BestCoder Round #16)
Revenge of LIS II Problem DescriptionIn computer science, the longest increasing subsequence problem ...
- HDU5086——Revenge of Segment Tree(BestCoder Round #16)
Revenge of Segment Tree Problem DescriptionIn computer science, a segment tree is a tree data struct ...
- UVA 816 - Abbott's Revenge(BFS)
UVA 816 - Abbott's Revenge option=com_onlinejudge&Itemid=8&page=show_problem&category=59 ...
- hdu 4099 Revenge of Fibonacci Trie树与模拟数位加法
Revenge of Fibonacci 题意:给定fibonacci数列的前100000项的前n位(n<=40);问你这是fibonacci数列第几项的前缀?如若不在前100000项范围内,输 ...
随机推荐
- process launch failed : failed to get the task for process xxx
原因: 证书问题,project和targets的证书都必须是开发证书,ADHOC的证书会出现此问题. 解决方案: project和targets的证书使用开发证书. 其他: This error ...
- 开发者应该避免使用的6个Java功能(转)
本文作者是一名拥有多年Java开发经验的程序员,他从经验中得出,并不是所有的Java SE功能/API都值得程序员去使用,比如本文列举的这6个,大家在使用前得慎重对待.以下是对原文的摘译. 多年的Ja ...
- Android基础知识、四大组件(转)
Android应用程序使用java语言编写的.Android SDK工具将所有的数据和资源文件以及代码进行编译,打包称为一个apk文件.一个apk文件中的所有代码被认为是一个应用,android系统的 ...
- scheme lambda表达式 形参
lambda表达式 (Lambda (arg1 …) exp1 exp2)从演算来看,(let ((var value) …) exp1 exp2…) == ((lambda (var …) exp ...
- BZOJ1264: [AHOI2006]基因匹配Match
1264: [AHOI2006]基因匹配Match Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 541 Solved: 347[Submit][S ...
- [Silverlight]常见问题
[Silverlight]常见问题 1. Silverlight项目是否支持ADO.NET对象? 不支持,Silverlight不支持常见的ADO.NET对象,如DataTable,DataSet,D ...
- 关于WebView的内存泄露 Leaked webview
[leaded webview 和WebView内存泄露问题解决方法] 解决方法1: 解决方法2 . 在Fragment回收Webview的时候注意一下. 就是讲他父控件里的内容清空: 参考:htt ...
- java笔记10之循环
关于for 循环语句:for循环,while循环,do...while循环. for循环格式: for(初始化语句;判断条件语句;控制条件语句) { ...
- 【mac开发.NET】No installed provisioning profiles match the installed iOS signing identities
编译错误提示 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets: Er ...
- Windows 驱动开发 - 5
上篇<Windows 驱动开发 - 4>我们已经完毕了硬件准备. 可是我们还没有详细的数据操作,比如接收读写操作. 在WDF中进行此类操作前须要进行设备的IO控制,已保持数据的完整性. 我 ...