0
点赞
收藏
分享

微信扫一扫

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



A. Golden System



time limit per test



memory limit per test



input



output


Piegirl got bored with binary, decimal and other integer based counting systems. Recently she discovered some interesting properties about number 

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

, 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 

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

.

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


100000.


Output


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


Sample test(s)


input


1000111


output


<


input


0010011


output


=


input


110101


output


>


Note

In the first example first number equals to 

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

, while second number is approximately1.6180339882, which is clearly a bigger number.

 ≈ 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

如上,后面最小为  (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;
}







举报

相关推荐

0 条评论