1. 程式人生 > >Revenge of Fibonacci hdu 5018

Revenge of Fibonacci hdu 5018

Problem Description 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 Hint For the third test case, the new Fibonacci sequence is: 2, 2, 4, 6, 10, 16, 26, 42, 68, 110…

Source BestCoder Round #10

map 去對映一下即可;

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include
<cstring>
#include<string> #include<cmath> #include<map> #include<set> #include<vector> #include<queue> #include<bitset> #include<ctime> #include<deque> #include<stack> #include<functional> #include<sstream> #include<cctype> //#pragma GCC optimize("O3") using namespace std; #define maxn 200005 #define inf 0x3f3f3f3f #define INF 0x7fffffff #define rdint(x) scanf("%d",&x) #define rdllt(x) scanf("%lld",&x) typedef long long ll; typedef unsigned long long ull; typedef unsigned int U; #define ms(x) memset((x),0,sizeof(x)) const int mod = 10000007; #define Mod 20100403 #define sq(x) (x)*(x) #define eps 1e-10 inline int rd() { int x = 0; char c = getchar(); bool f = false; while (!isdigit(c)) { if (c == '-') f = true; c = getchar(); } while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } return f ? -x : x; } ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); } ll sqr(ll x) { return x * x; } map<ll, int>Map; ll fib[200]; int main() { //ios::sync_with_stdio(false); int T; cin >> T; while (T--) { ll A, B, C; ms(fib); Map.clear(); rdllt(A); rdllt(B); rdllt(C); fib[1] = A; fib[2] = B; Map[A] = 1; Map[B] = 1; for (int i = 3; i <= 46; i++) { fib[i] = fib[i - 1] + fib[i - 2]; Map[fib[i]] = 1; } if (Map[C])cout << "Yes" << endl; else cout << "No" << endl; } }