51NOD 1491 黄金系统 && Codeforces 458 A. Golden System(斐波那契数列 + 找规律)

传送门
q = 5+12 在黄金系统下面 a0a1...an 等于 ni=0aiqni ,其中 ai 0 或者 1

现在给出两个黄金系统下面的数字,请比较他们的大小。

Input

单组测试数据。

第一行有一个字符串 a

第二行有一个字符串 b

他们都是非空串,可能有前导 0 ,并且只有 0 1 组成,长度不超过 100000

Output

如果 a>b ,输出 >

如果 a b,输出 =

如果 a<b,输出 < <script type="math/tex" id="MathJax-Element-4893"><</script>;

Input示例

00100
11

Output示例

=

解题思路:

其实通过样例我们可以发现这样一个规律: qn = qn1 + qn2 ,那么我们现在知道这个规律

我们就可以,通过将所有 ai 1 的 用一个数组 f 保存下来,如果是 字符串 a 的话 f[ni1]

就加加,如果是 b 的话,就减减, 然后一步步转移到 f[0]  f[1] 上,然后判断这两个数就行

了。因为中间转移的时候 会爆 long long 所以,我们将 f 数组定义成一个 double 的就可以了,

就最后判断 一下 qf[1]+f[0] 的符号就行了。

My Code

/**
2016 - 08 - 19 下午
Author: ITAK

Motto:

今日的我要超越昨日的我,明日的我要胜过今日的我,
以创作出更好的代码为目标,不断地超越自己。
**/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9+5;
const int MAXN = 1e5+5;
const int MOD = 1e9+7;
const double eps = 1e-7;
const double PI = acos(-1);
using namespace std;
LL Scan_LL()///输入外挂
{
    LL res=0,ch,flag=0;
    if((ch=getchar())=='-')
        flag=1;
    else if(ch>='0'&&ch<='9')
        res=ch-'0';
    while((ch=getchar())>='0'&&ch<='9')
        res=res*10+ch-'0';
    return flag?-res:res;
}
int Scan_Int()///输入外挂
{
    int res=0,ch,flag=0;
    if((ch=getchar())=='-')
        flag=1;
    else if(ch>='0'&&ch<='9')
        res=ch-'0';
    while((ch=getchar())>='0'&&ch<='9')
        res=res*10+ch-'0';
    return flag?-res:res;
}
void Out(LL a)///输出外挂
{
    if(a>9)
        Out(a/10);
    putchar(a%10+'0');
}
char a[MAXN], b[MAXN];
double f[MAXN];
int main()
{
    while(~scanf("%s%s",a,b))
    {
        int lena = strlen(a);
        int lenb = strlen(b);
        memset(f, 0, sizeof(f));
        for(int i=0; i<lena; i++)
            if(a[i] == '1')
                f[lena-i-1]++;
        for(int i=0; i<lenb; i++)
            if(b[i] == '1')
                f[lenb-i-1]--;
        int tmp = max(lena, lenb);
        for(int i=tmp-1; i>=2; i--)
        {
            f[i-1] += f[i];
            f[i-2] += f[i];
        }
        if(!f[0] && !f[1])
        {
            puts("=");
            continue;
        }
        double ans = (sqrt(5.0)+1)*0.5*f[1] + f[0];
        if(ans < 0.0)
            puts("<");
        else
            puts(">");
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值