Codeforces 458A Golden System
来源:互联网 发布:办公网络 编辑:程序博客网 时间:2024/05/02 00:34
题目来源http://codeforces.com/contest/458/problem/A
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 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.
Print ">" if the first number is larger, "<" if it is smaller and "=" if they are equal.
1000111
<
不难发现从最高位开始推,一旦有两位相差大于等于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;}
- Codeforces 458A Golden System
- Codeforces 458A Golden System
- 【CodeForces】458A - Golden System(数论 & 模拟)
- 51nod 1491|CodeForces 458A Golden System(数论 )
- A. Golden System
- 51NOD 1491 黄金系统 && Codeforces 458 A. Golden System(斐波那契数列 + 找规律)
- CF 457A(Golden System-特殊的进制)
- The Golden Age CodeForces
- CodeForces#313 A. Currency System in Geraldion
- codeforces 560 A. Currency System in Geraldion
- CodeForces 560A Currency System in Geraldion
- CodeForces 560A Currency System in Geraldion
- CodeForces 560A Currency System in Geraldion
- CodeForces 560A Currency System in Geraldion
- Codeforces 214A System of Equations
- CodeForces 560A Currency System in Geraldion
- CodeForces - 560A Currency System in Geraldion
- codeforces 214A System of Equations
- 简单XML操作类
- AJAX参数传递时候如何使用JSON
- UVA - 10935 Throwing cards away I
- sdutoj 队列之排队买饭
- 嵌入式学习的误区及建议(软件硬件)
- Codeforces 458A Golden System
- Voldemort博客
- Android -- 视频音频多媒体播放,在线播放, MediaPlayer, SurfaceView, SoundPool, Timer定时器使用
- C++实现委托的几种方法(摘录)
- Android 数据分析系列一:sharedPreferences
- git操作等常用命令
- 【Splay】BZOJ 1588 [HNOI2002]营业额统计
- 第三节:闪电特效
- 函数指针与指针函数