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项范围内,输 ...
随机推荐
- SegmentReader 批量 dump
/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agree ...
- poj 3114 Countries in War
http://poj.org/problem?id=3114 #include <cstdio> #include <cstring> #include <queue&g ...
- 尽历磨难,搞定OPEN VSWITCH安装
参考贴: http://sudomakeinstall.com/linux-systems/installing-openvswitch-on-centos-6-6-5 yum install ker ...
- VitamioBundle-master
1. 下载资源 (1) 核心插件 VitamioBundle 下载地址:https://github.com/yixia/VitamioBundle (2) 官方示例 VitamioDemo 下载地址 ...
- NEW关键字的三种用法
最近面试中有一道题是写new关键字的几种用法,想了下写下我知道的两种用法 第一种 创建对象.调用构造函数,这就不用讲了 ClassA A=new ClassA(); 第二种 是作为修饰符,显示隐藏继 ...
- selenium webdriver python 元素定位
总结 定位查找时,返回查找到的第一个match的元素.如果找不到,则 raise NoSuchElementException 单个元素定位: find_element_by_idfind_e ...
- linux之utime函数解析
[lingyun@localhost utime]$ ls hello utime.c world [lingyun@localhost utime]$ cat utime.c /******* ...
- Sublime Text3 配置markdown插件
sublime是一个亮骚的文本编辑器,而且是跨三大平台,而markdown是一门标记语法,对于记录真是神器,具体语法百度很多,下面教你在sublime上配置markdown. 这两个神器结合起来简直好 ...
- Oracle's Business Intelligence Applications Configuration Manager 基本概念
Oracle's Business Intelligence Applications Configuration Manager :BIACM Once the BIAPPS installatio ...
- Spring MVC中使用Mongodb总结
近期项目做了次架构调整,原来是使用MySQL+GeoHash来存储LBS数据(地理位置信息),现在使用NOSQL数据库MongoDB来存储LBS数据(地理位置信息).由于项目是基于spring MVC ...