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项范围内,输 ...
随机推荐
- Hazelcase 简介
原博客地址:http://blog.csdn.net/zhu_tianwei/article/details/47984599 Hazelcast是一种内存数据网格in-memory data gri ...
- 转:基于科大讯飞语音API语音识别开发详解
原文来自于: http://www.52wulian.org/android_voice/ 最近项目需要用到android语音识别,立马就想到科大讯飞,结合官方实例及阅读API文档,初步的完成了And ...
- JSP前端总结
一.C标签 一] <c:out value="..." default="..." escapeXml="true"> ...
- VS2010中水晶报表应用及实例
原文:VS2010中水晶报表应用及实例 基本分类如下:第一部分:VS2010简介VS2010是微软的提供的一套完整的开发环境,功能也是相当的大微软宣布了下一代开发工具和平台的正式名称,分别称为“Vis ...
- 【数学】XMU 1597 GCD
题目链接: http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1597 题目大意: 求(am-bm, an-bn),结果取模1000000007,a,b ...
- Android新浪微博客户端(六)——Home界面的ListView
原文出自:方杰|http://fangjie.info/?p=184转载请注明出处 最终效果演示:http://fangjie.info/?page_id=54该项目代码已经放到github:http ...
- WPF: How to use DatePicker in XAML-DataGrid
https://msdn.microsoft.com/en-us/library/system.windows.controls.datagridtemplatecolumn(v=VS.100).as ...
- 阳光餐厅--oracle---建表---danrong
select * from manager; select * from dish; select * from board; select * from employee; select * fro ...
- 用MFC完成一个简单的猜数字游戏: 输入的四位数中,位置和数字都正确为A,数字相同而位置不同的为B。
最近学习了MFC一些比较基础的知识,所以打算通过做一个简单的数字游戏来理解MFC的流程并进一步熟悉其操作. 在这里,我做了一个猜数字的小游戏.第一步当然是设计主界面,先给大家展示一下游戏界面: 主界面 ...
- hdu3308LCIS(线段树,点更新,段查寻,查寻时一定要注意跨越时如何计算)
Problem Description Given n integers. You have two operations: U A B: replace the Ath number by B. ( ...