Codeforces 458A Golden System

来源:互联网 发布:办公网络 编辑:程序博客网 时间:2024/05/02 00:34

 题目来源http://codeforces.com/contest/458/problem/A

A. Golden System

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
1000111
output
<
题意是说给定两个串比较他们的大小,这两个串是黄金进制也就是说 q2 = q + 1 即 100 = 011;

不难发现从最高位开始推,一旦有两位相差大于等于2,就能说明两个串的大小关系,如果没有再比较最后两位。

参考tourist的代码写的:

#include<cstdio>#include<cmath>#include<cstring>const int Maxn=100009;const double eps=1e-8;char str[Maxn];int a[Maxn];int main(){int maxn=0,n;for(int i=1;i>=-1;i=i-2){scanf("%s",str);n=strlen(str);if(n>maxn) maxn=n;for(int j=0;j<n;j++){if(str[n-j-1]-'0'==1) a[j] +=i;}}for(int i=maxn-1;i>=2;i--){if(a[i]>=2) {printf(">\n");return 0;}else if(a[i]<=-2){printf("<\n");return 0;}a[i-1]+=a[i];a[i-2]+=a[i];}double q=(sqrt(5.0)+1)/2;double p=a[1]*q+a[0];if(p>eps) printf(">\n");else if(p<-eps) printf("<\n");else printf("=\n");return 0;} 

0 0
原创粉丝点击