MemSQL Start[c]UP 2.0 - Round 2 - Online Round(数学:高精度)

A. Golden System
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Piegirl got bored with binary, decimal and other integer based counting systems. Recently she discovered some interesting properties about number , in particular that q2 = q + 1, and she thinks it would make a good base for her new unique system. She called it "golden system". In golden system the number is a non-empty string containing 0's and 1's as digits. The decimal value of expression a0a1...an equals to .

Soon Piegirl found out that this system doesn't have same properties that integer base systems do and some operations can not be performed on it. She wasn't able to come up with a fast way of comparing two numbers. She is asking for your help.

Given two numbers written in golden system notation, determine which of them has larger decimal value.

Input

Input consists of two lines — one for each number. Each line contains non-empty string consisting of '0' and '1' characters. The length of each string does not exceed 100000.

Output

Print ">" if the first number is larger, "<" if it is smaller and "=" if they are equal.

Sample test(s)
input
1000
111
output
<
input
00100
11
output
=
input
110
101
output
>
Note

In the first example first number equals to , while second number is approximately1.6180339882 + 1.618033988 + 1 ≈ 5.236, which is clearly a bigger number.

In the second example numbers are equal. Each of them is  ≈ 2.618.


一道很蛋疼的题,根据 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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值