您的位置:首页 > 编程语言 > Go语言

CF457A:Golden System(数论 & 进制)

2017-08-13 22:33 260 查看
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.

Examples

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 approximately 1.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^i = q^(i-1) + q^(i-2),那么将高位的数累加最低两位即可比较大小。

# include <bits/stdc++.h>using namespace std;
const int maxn = 1e5+30;
typedef long long LL;
char s1[maxn], s2[maxn];
double a[maxn];
int main()
{
scanf("%s%s",s1,s2);
int n1=strlen(s1), n2 = strlen(s2);
for(int i=0; i<n1/2; ++i) swap(s1[i], s1[n
df62
1-i-1]);
for(int i=0; i<n2/2; ++i) swap(s2[i],s2[n2-i-1]);
for(int i=0; i<n1; ++i) a[i] = s1[i]-'0';
for(int i=0; i<n2; ++i) a[i] = a[i] - s2[i] + '0';
for(int i=max(n1,n2)-1; i>=2; --i)
{
a[i-2] += a[i];
a[i-1] += a[i];
}
if(a[0] == a[1] && a[0] == 0)
puts("=");
else
{
double ans = (sqrt(5)+1)/2.0*a[1] + a[0];
if(ans < 0) puts("<");
else puts(">");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: