CF memsql Start[c]UP 2.0 A
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的更多相关文章
- 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 ...
- 【CF MEMSQL 3.0 A. Declined Finalists】
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- 【CF MEMSQL 3.0 E. Desk Disorder】
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- 【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 ...
- 【CF MEMSQL 3.0 C. Pie Rules】
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- 【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 ...
- 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 ...
- MemSQL Start[c]UP 2.0 - Round 2 - Online Round
搞到凌晨4点一个没出,要gg了. A. Golden System http://codeforces.com/contest/458/problem/A #include<cstdio> ...
- MemSQL Start[c]UP 2.0 - Round 1
A. Eevee http://codeforces.com/contest/452/problem/A 字符串水题 #include<cstdio> #include<cstrin ...
随机推荐
- 【2016-11-13】【坚持学习】【Day25】【Oracle 查询某一字段最大值】
partition 分组order by 以哪一个字段排序 select n.* ,row_number()over(partition by n.type order by n.createtime ...
- springboot Serving Web Content with Spring MVC
Serving Web Content with Spring MVC This guide walks you through the process of creating a "hel ...
- transactionManager的type与dataSource的type
1. 在ibatis的配置文件中dataSource 节点有这么个配置<datasource type="SIMPLE"></datasource>,根据原 ...
- poj[1187][Noi 01]陨石的秘密
Description 公元11380年,一颗巨大的陨石坠落在南极.于是,灾难降临了,地球上出现了一系列反常的现象.当人们焦急万分的时候,一支中国科学家组成的南极考察队赶到了出事地点.经过一番侦察,科 ...
- Javascript函数式编程要掌握的知识点讲解
一:理解call和apply 及arguments.callee ECMAScript3给Function的原型定义了两个方法,他们是Function.prototype.call 和 Functio ...
- play with make
1) the VPATH variable In make world, the VPATH variable guide you where to find the .c/.o file 2) th ...
- cf Round 607
A.Chain Reaction(DP+二分) 题意:一排有n个灯塔,每个灯塔给出坐标xi和力量yi,每次从最右边依次点亮灯塔,每点亮一个灯塔,它左边的距离它yi范围内的灯塔将受到损坏.现在允许在最右 ...
- JavaScript类库---JQuery(一)
1.基础: Jquery类库定义了一个全局函数:JQuery(); 别名$.是JQuery在全局命名空间中定义的唯一两个变量.返回一个新创建的JQuery对象: 另:JQuery中定义的许多方法返回值 ...
- 详解AsyncTask的使用
转载自:http://blog.csdn.net/liuhe688/article/details/6532519 在Android中实现异步任务机制有两种方式,Handler和AsyncTask. ...
- LCA最近公共祖先 ST+RMQ在线算法
对于一类题目,是一棵树或者森林,有多次查询,求2点间的距离,可以用LCA来解决. 这一类的问题有2中解决方法.第一种就是tarjan的离线算法,还有一中是基于ST算法的在线算法.复杂度都是O( ...