CF memsql Start[c]UP 2.0 A

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.

思路:最开始想推每一项的公式,不行,系数太大!后来想把前面的1全部转化为后面的1,发现这样的话也会2^100000太大!

后来发现如果一个字符串中出现的第一个1比另一个字符串中的第一个1高两位的话,就是这个串大,否则转化为后面的1(也就是第i位的1等于第i-1位的1和第i-2位的1)然后再逐位判断对多10^5。

处理时要把字符串反转,放在vector里面然后reverse(),竟然超时,换做直接字符串反转函数,AC 30ms!

 #include<cstdio>

 #include<iostream>

 #include<cmath>

 #include<stdlib.h>

 #include<vector>

 #include<cstring>

 #include<map>

 #include<algorithm>

 #include<string.h>

 #define M(a,b) memset(a,b,sizeof(a))

 #define INF 0x3f3f3f3f

 using namespace std;

 char a[],b[];

 int num[];

 vector<char> v1,v2;

 void strRev(char *s)

 {

     char temp, *end = s + strlen(s) - ;

     while( end > s)

     {

         temp = *s;

         *s = *end;

         *end = temp;

         --end;

         ++s;

     }

 }

 int main()

 {

     while(scanf("%s",a)==)

     {

         scanf("%s",b);

         int n = max(strlen(a),strlen(b));

         strRev(a);

         strRev(b);

         int strla = strlen(a);

         int strlb = strlen(b);

         int tem = strlen(a)-strlen(b);

         if(tem < )

         {

             for(int i = ;i<-tem;i++)

                 a[strla+i] = '';

         }

         else

         {

             for(int i = ;i<tem;i++)

                 b[strlb+i] = '';

         }

         /*for(int i = 0;i<n;i++) cout<<a[i];

         cout<<endl;

          for(int i = 0;i<n;i++) cout<<b[i];

         cout<<endl;*/

         for(int i = ;i<n;i++)

         {

             if(a[i] == '' && b[i] == '') num[i+] = ;

             else if(a[i] == '' && b[i] == '') num[i+] = ;

             else if(a[i] == '' && b[i] == '') num[i+] = ;

             else if(a[i] == '' && b[i] == '') num[i+] = -;

         }

         num[] = ;

         num[] = ;

         //for(int i = 0;i<n+2;i++) cout<<num[i];

         //cout<<endl;

         for(int i = n+;i>=;i--)

         {

             if(i==&&num[i]==) puts("=");

             if(num[i]==){puts(">"); break;}

             if(num[i]==-){puts("<"); break;}

             if(num[i] == ) continue;

             if(num[i] == )

             {

                 if(num[i-]==||num[i-]==) {puts(">"); break;}

                 if(num[i-]==-) num[i-]+=, num[i-]+=;

             }

             if(num[i] == -)

             {

                 if(num[i-]==||num[i-]==-) {puts("<"); break;}

                 if(num[i-]==) num[i-]-=, num[i-]-=;

             }

         }

     }

     return ;

 }

CF memsql Start[c]UP 2.0 A的更多相关文章

  1. CF memsql Start[c]UP 2.0 B

    CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...

  2. 【CF MEMSQL 3.0 A. Declined Finalists】

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  3. 【CF MEMSQL 3.0 E. Desk Disorder】

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  4. 【CF MEMSQL 3.0 D. Third Month Insanity】

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  5. 【CF MEMSQL 3.0 C. Pie Rules】

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  6. 【CF MEMSQL 3.0 B. Lazy Security Guard】

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  7. MemSQL Start[c]UP 2.0 - Round 1(无聊练手B题)

    http://codeforces.com/contest/452/problem/B   B. 4-point polyline time limit per test 2 seconds memo ...

  8. MemSQL Start[c]UP 2.0 - Round 2 - Online Round

    搞到凌晨4点一个没出,要gg了. A. Golden System http://codeforces.com/contest/458/problem/A #include<cstdio> ...

  9. MemSQL Start[c]UP 2.0 - Round 1

    A. Eevee http://codeforces.com/contest/452/problem/A 字符串水题 #include<cstdio> #include<cstrin ...

随机推荐

  1. springmvc 上传下载

    springmvc文件上传下载在网上搜索的代码 参考整理了一份需要使用的jar.commons-fileupload.jar与commons-io-1.4.jar 二个文件 1.表单属性为: enct ...

  2. 计算机网络-IP类型判断

    第一个类别为A类,最后一个类别为E类,前边三个类别(A类.B类和C类)被用来标识工作站.路由器.交换机以及其他设备,而最后两个类别(D类和E类)被保留做特殊用途. 一个IP地址由32个比特位构成,这就 ...

  3. js数组中的常用方法总结

    栈方法(后进先出) ArrayObj.push()方法 ArrayObj.pop()方法 ArrayObj.push():就是向数组末尾添加新的元素,返回的是数组新的长度.ArrayObj.pop() ...

  4. Shell(C++实现,CodeBlocks+GCC编译)

    程序效果: 只实现了login .cd .ls .cat 四个命令.而且只能在 Windows 下运行. 代码: //main.cpp 1 #include <iostream> #inc ...

  5. CF733C Epidemic in Monstropolis[模拟 构造 贪心]

    C. Epidemic in Monstropolis time limit per test 1 second memory limit per test 256 megabytes input s ...

  6. 洛谷P1373 小a和uim之大逃离[背包DP]

    题目背景 小a和uim来到雨林中探险.突然一阵北风吹来,一片乌云从北部天边急涌过来,还伴着一道道闪电,一阵阵雷声.刹那间,狂风大作,乌云布满了天空,紧接着豆大的雨点从天空中打落下来,只见前方出现了一个 ...

  7. iOS Webview 实现修改javascript confirm 和 alert

    贴代码: @interface UIWebView (JavaScriptAlert) -(void) webView:(UIWebView *)sender runJavaScriptAlertPa ...

  8. JS实现Observable观察者模式

    欢迎讨论与交流 : ) 注 代码参考自——汇智网 RxJS教程 前言 Observable观察者模式令小白笔者眼前一亮.数据生产者(observable)负责生产新鲜的数据,同时在生产完毕后'通知“消 ...

  9. mysql: Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '= 的解决

    昨天把mysql里所有table的varchar字段的字符集,批量换成了utf8mb4/utf8mb4_unicode_ci ,以便能保存一些emoji火星文 , 结果有一个sql语句执行时,报错如下 ...

  10. 让C#可以像Javascript一样操作Json

    Json的简介 JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于ECMAScript的一个子集. JSON采用完全独立于语言的文本格式,但是也使用了 ...