一道很蛋疼的题,根据 q2 = q + 1很容易想到斐波那契数列上去。。。
我之前的做法是从前面开始取每3位比较一次,临睡的时候发现这种思路根本是错的
比如一个数为1000...而另一个数为01011...这样的话我的结果是前面的数比较大,但其实结果无法确定
这个题的应用就在于把100 == 011,这样从高位向低位转化,最后只剩下a[0], a[1]两项,再确定结果
看了下别人的代码,用一个数组a先用+处理str1,再用-处理str2
我用a数组+处理str1, 用b数组-处理str2,最后用a[1] a[0] b[1] b[0]确定结果,但是怎么写都跪
这道题也真够蛋疼的
代码如下:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAXN 100100
using namespace std;
int len1, len2, len;
char str1[MAXN], str2[MAXN];
long double a[MAXN];
int main(void) {
scanf("%s", str1);
len1 = strlen(str1);
reverse(str1, str1+len1);
for(int i=0; i<len1; ++i)
a[i] += str1[i]-'0';
scanf("%s", str2);
len2 = strlen(str2);
reverse(str2, str2+len2);
for(int i=0; i<len2; ++i)
a[i] -= str2[i]-'0';
len = max(len1, len2);
for(int i=len-1; i>1; --i)
if(a[i]) {
a[i-1] += a[i];
a[i-2] += a[i];
a[i] = 0;
}
if(fabs(a[0])<1e-5 && fabs(a[1])<1e-5)
puts("=");
else puts((a[1]*(sqrt(5)+1)>-2*a[0]) ? ">" : "<");
return 0;
}