CF 457A(Golden System-特殊的进制)

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 expressiona0a1...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.


本题不能用正常2进制比较。

但是有另外的性质 q^k=q^(k-1)+q^(k-2)

仔细观察得到等式2q^k>=q^(k-1)+q^(k-2)+...+q^0

如果2数都化为只有1,2位的数会溢出

所以将2数相减与0比较。

令由公式知不断向后加,若有一位>=2或<=-2则正负可知

(2后面那位数即使经过相加,由于要么都之前这位都+(-)1 ) 所以不会出现 -(+)2

0   0    2     -1

    +1  +1

  +1   +1

如上,后面最小为  (2 ,0 ,-1,-1,...,-1)   还是正的



#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])  
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define MAXN (100000+10)
#define eps (1e-3)
long long mul(long long a,long long b){return (a*b)%F;}
long long add(long long a,long long b){return (a+b)%F;}
long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;}
typedef long long ll;
char s1[MAXN],s2[MAXN];
ll a[MAXN]={0},b[MAXN]={0};
void pushdown(ll a[],int i)
{
	a[i-1]+=a[i],a[i-2]+=a[i];
	a[i]=0;
}
int main()
{
//	freopen("CF457A.in","r",stdin);
//	freopen(".out","w",stdout);
		
	scanf("%s%s",s1,s2);
	int n1=strlen(s1),n2=strlen(s2);
	
	Rep(i,n1/2) swap(s1[i],s1[n1-i-1]);	
	Rep(i,n2/2) swap(s2[i],s2[n2-i-1]);	
	
	For(i,n1) a[i]=s1[i-1]-'0';
	For(i,n2) b[i]=s2[i-1]-'0';	
	
//	For(i,n1) cout<<a[i];cout<<endl;
//	For(i,n2) cout<<b[i];cout<<endl;

	int n=max(n1,n2);
	ForD(i,n) a[i]-=b[i];
	ForkD(i,3,n)
	{
		if (a[i]>=2) {cout<<'>'<<endl;return 0;	}
		else if (a[i]<=-2) {cout<<'<'<<endl;return 0;	}
		pushdown(a,i);
	}

	
//	For(i,n1) cout<<a[i];cout<<endl;
//	For(i,n2) cout<<b[i];cout<<endl;

	const double q=(1+sqrt(5))/2;
	
	double p=a[1]+a[2]*q;
	
	if (p>eps) putchar('>');
	else if (p<-eps) putchar('<');
	else putchar('=');
	putchar('\n');
	
	return 0;
}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值