hdu 5018

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;
}
上一篇:RedHat6.4 用UDEV配置ASM所需磁盘


下一篇:链式前向星图存储优化