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!

  1. #include<cstdio>
  2.  
  3. #include<iostream>
  4.  
  5. #include<cmath>
  6.  
  7. #include<stdlib.h>
  8.  
  9. #include<vector>
  10.  
  11. #include<cstring>
  12.  
  13. #include<map>
  14.  
  15. #include<algorithm>
  16.  
  17. #include<string.h>
  18.  
  19. #define M(a,b) memset(a,b,sizeof(a))
  20.  
  21. #define INF 0x3f3f3f3f
  22.  
  23. using namespace std;
  24.  
  25. char a[],b[];
  26.  
  27. int num[];
  28.  
  29. vector<char> v1,v2;
  30.  
  31. void strRev(char *s)
  32.  
  33. {
  34.  
  35. char temp, *end = s + strlen(s) - ;
  36.  
  37. while( end > s)
  38.  
  39. {
  40.  
  41. temp = *s;
  42.  
  43. *s = *end;
  44.  
  45. *end = temp;
  46.  
  47. --end;
  48.  
  49. ++s;
  50.  
  51. }
  52.  
  53. }
  54.  
  55. int main()
  56.  
  57. {
  58.  
  59. while(scanf("%s",a)==)
  60.  
  61. {
  62.  
  63. scanf("%s",b);
  64.  
  65. int n = max(strlen(a),strlen(b));
  66.  
  67. strRev(a);
  68.  
  69. strRev(b);
  70.  
  71. int strla = strlen(a);
  72.  
  73. int strlb = strlen(b);
  74.  
  75. int tem = strlen(a)-strlen(b);
  76.  
  77. if(tem < )
  78.  
  79. {
  80.  
  81. for(int i = ;i<-tem;i++)
  82.  
  83. a[strla+i] = '';
  84.  
  85. }
  86.  
  87. else
  88.  
  89. {
  90.  
  91. for(int i = ;i<tem;i++)
  92.  
  93. b[strlb+i] = '';
  94.  
  95. }
  96.  
  97. /*for(int i = 0;i<n;i++) cout<<a[i];
  98.  
  99. cout<<endl;
  100.  
  101. for(int i = 0;i<n;i++) cout<<b[i];
  102.  
  103. cout<<endl;*/
  104.  
  105. for(int i = ;i<n;i++)
  106.  
  107. {
  108.  
  109. if(a[i] == '' && b[i] == '') num[i+] = ;
  110.  
  111. else if(a[i] == '' && b[i] == '') num[i+] = ;
  112.  
  113. else if(a[i] == '' && b[i] == '') num[i+] = ;
  114.  
  115. else if(a[i] == '' && b[i] == '') num[i+] = -;
  116.  
  117. }
  118.  
  119. num[] = ;
  120.  
  121. num[] = ;
  122.  
  123. //for(int i = 0;i<n+2;i++) cout<<num[i];
  124.  
  125. //cout<<endl;
  126.  
  127. for(int i = n+;i>=;i--)
  128.  
  129. {
  130.  
  131. if(i==&&num[i]==) puts("=");
  132.  
  133. if(num[i]==){puts(">"); break;}
  134.  
  135. if(num[i]==-){puts("<"); break;}
  136.  
  137. if(num[i] == ) continue;
  138.  
  139. if(num[i] == )
  140.  
  141. {
  142.  
  143. if(num[i-]==||num[i-]==) {puts(">"); break;}
  144.  
  145. if(num[i-]==-) num[i-]+=, num[i-]+=;
  146.  
  147. }
  148.  
  149. if(num[i] == -)
  150.  
  151. {
  152.  
  153. if(num[i-]==||num[i-]==-) {puts("<"); break;}
  154.  
  155. if(num[i-]==) num[i-]-=, num[i-]-=;
  156.  
  157. }
  158.  
  159. }
  160.  
  161. }
  162.  
  163. return ;
  164.  
  165. }

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. WPF 3D 知识点大全以及实例

    引言 现在物联网概念这么火,如果监控的信息能够实时在手机的客服端中以3D形式展示给我们,那种体验大家可以发挥自己的想象. 那生活中我们还有很多地方用到这些,如上图所示的Kinect 在医疗上的应用,当 ...

  2. 在github上建立自己的网站

    学了前端小半年,如今写了个自己的网页想要去应聘,却发现部署很麻烦,部署到阿里云之类,买域名啊啥的还要收费,说贵也不贵,但我就是傲娇~ google一下了解到Github有一个Github pages的 ...

  3. 洛谷P1462 通往奥格瑞玛的道路[二分答案 spfa 离散化]

    题目背景 在艾泽拉斯大陆上有一位名叫歪嘴哦的神奇术士,他是部落的中坚力量 有一天他醒来后发现自己居然到了联盟的主城暴风城 在被众多联盟的士兵攻击后,他决定逃回自己的家乡奥格瑞玛 题目描述 在艾泽拉斯, ...

  4. 第1章 重构,第一个案例(1):糟糕的statement函数设计

    1. 启航:影片出租,计算每一位顾客的消费金额并打印清单 1.1 场景说明: (1)影片分类规则:普通片.儿童片和新片等3类 (2)每种影片计算租金的方式. ①普通片:基本租金为2元,超过2天的部分每 ...

  5. python的历史

    Python的诞生 Python的创始人吉多·范罗苏姆(Guido van Rossum),在1989年12月的圣诞节期间,为了打发时间,决定开发一种新的脚本解释程序,作为ABC语言的继承. 现在,p ...

  6. 2016-2017-2《程序设计与数据结构》学生博客&git@OSC

    2016-2017-2<程序设计与数据结构>学生博客&git@OSC 博客园 20162301张师瑜 20162302杨京典 20162303石亚鑫 20162304张浩林 201 ...

  7. 微信开发 企业号(二)-- 回调模式之Tooken验证 .net/python

    在企业号开发者中心中,有加密解密源代码,供给开发者使用.(加解密库下载) 由于官方只提供了python2.*的类库,使用python3.*的朋友可以再最后下载我修改后的py文件(仅修改验证Tooken ...

  8. ionic android双击退出应用和物理返回按钮隐藏键盘的实现

    angular.module('starter', ['ionic', 'route', 'config', 'global', 'commonJs', 'ngCordova']) .run(['$i ...

  9. js的this上下文的坑

    很明显,this这个坑,在多层嵌套的时候还是一样被废,不管是call, apply还是bind. 例如: var fun = function() { this.name = 'test'; var ...

  10. How To Set Up an OpenVPN Server on Ubuntu 14.04

    Prerequisites The only prerequisite is having a Ubuntu 14.04 Droplet established and running. You wi ...