hdu 5018

来源:互联网 发布:网络蜘蛛bt 编辑:程序博客网 时间:2024/06/16 21:08

http://acm.hdu.edu.cn/showproblem.php?pid=5018

任意给你三个数,让你判断第三个数是否在以前两个数为开头组成的Fibonacci 数列中。

直接暴力

#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include <queue>#include <vector>#include<set>#include <iostream>#include <algorithm>using namespace std;#define RD(x) scanf("%d",&x)#define RD2(x,y) scanf("%I64d%I64d",&x,&y)#define clr0(x) memset(x,0,sizeof(x))typedef long long LL;LL a,b,c,d;void work(){    RD2(a,b);scanf("%I64d",&c);    bool flag = false;    if(a == c || b == c){        cout<<"Yes"<<endl;        return;    }    while(b < c){        d = b+a;        if(d == c){            cout<<"Yes"<<endl;            return;        }        else if(d > c){            cout<<"No"<<endl;            return;        }        a = b,b = d;    }    cout<<"No"<<endl;    return;}int main() {    int _;    RD(_);    while(_--){        work();    }    return 0;}


0 0
原创粉丝点击