The standard interpretation of the binary number 1010 is 8 + 2 = 10. An alternate way to view the sequence “1010” is to use Fibonacci numbers as bases instead of powers of two. For this problem, the terms of the Fibonacci sequence are:
1,2,3,5,8,13,21,...1, 2, 3, 5, 8, 13, 21, . . .1,2,3,5,8,13,21,...
    Where each term is the sum of the two preceding terms (note that there is only one 1 in the sequence as defined here). Using this scheme, the sequence “1010” could be interpreted as 1·5+0·3+1·2+0·1 = 7. This representation is called a Fibinary number.
    Note that there is not always a unique Fibinary representation of every number. For example the number 10 could be represented as either 8 + 2 (10010) or as 5 + 3 + 2 (1110). To make the Fibinary representations unique, larger Fibonacci terms must always be used whenever possible (i.e. disallow 2 adjacent 1’s). Applying this rule to the number 10, means that 10 would be represented as 8+2 (10010).
    Write a program that takes two valid Fibinary numbers and prints the sum in Fibinary form.
Input
The input file contains several test cases with a blank line between two consecutive.
    Each test case consists in two lines with Fibinary numbers. These numbers will have at most 100 digits.
Output
For each test case, print the sum of the two input numbers in Fibinary form.
    It must be a blank line between two consecutive outputs.
Sample Input
10010
1

10000
1000

10000
10000
Sample Output
10100

100000

100100

问题链接:UVA763 LA5339 Fibinary Numbers
问题简述:(略)
问题分析:大数问题,用Java来解决。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的Java语言程序如下:

/* UVA763 LA5339 Fibinary Numbers */import java.util.Scanner;
import java.math.BigInteger;public class Main {static BigInteger getd(String a, BigInteger fib[]) {BigInteger ret = BigInteger.ZERO;for(int i = 0; i < a.length(); i++)if(a.charAt(i) == '1')ret = ret.add(fib[a.length() - 1 - i]);return ret;}public static void main(String args[]){int N = 200;Scanner input = new Scanner(System.in);BigInteger fib[] = new BigInteger[200];fib[0]=BigInteger.ONE;fib[1]=BigInteger.valueOf(2);for (int i = 2; i < N; i++)fib[i] = fib[i - 1].add(fib[i - 2]);int flag = 0;while(input.hasNext()) {if (flag == 1) System.out.println("");flag = 1;BigInteger ans = BigInteger.ZERO;String a = input.next();ans = getd(a, fib);a = input.next();ans = ans.add(getd(a, fib));int flag2 = 0;for(int i = N - 1; i >= 0; i--) {if(ans.compareTo(fib[i]) >= 0) {flag2 = 1;System.out.print("1");ans = ans.subtract(fib[i]);}else if(flag2 == 1) System.out.print("0");}if(flag2 == 0) System.out.print("0");System.out.println();}}
}

UVA763 LA5339 Fibinary Numbers【大数】相关推荐

  1. Fibinary Numbers

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=30506#problem/V 题意:从右向左,每一个位数,分别表示一个fibonacci数 ...

  2. 大数斐波那契数列+取余

    斐波那契序列 集锦 (转) [定理1] 标准Fibonacci序列(即第0项为0,第1项为1的序列)当N大于1时,一定有f(N)和f(N-1)互质 其实,结合"互质"的定义,和一个 ...

  3. 斐波那契序列 Fibonacci

    [定理1] 标准Fibonacci序列(即第0项为0,第1项为1的序列)当N大于1时,一定有f(N)和f(N-1)互质 其实,结合"互质"的定义,和一个很经典的算法就可以轻松证明 ...

  4. 斐波那契数列谈矩阵(1)

    斐波那契序列 集锦 (转) [定理1] 标准Fibonacci序列(即第0项为0,第1项为1的序列)当N大于1时,一定有f(N)和f(N-1)互质 其实,结合"互质"的定义,和一个 ...

  5. 数字图像处理 python_5使用Python处理数字的高级操作

    数字图像处理 python Numbers are everywhere in our daily life - there are phone numbers, dates of birth, ag ...

  6. 中英保险业务常用词汇--产险

    1.       Actual Cash Policy(实际现金价值保险单): 实际现金价值保险单系以保险标的之实际现金价值为赔偿金额,有别于以固定保险金额承保某一保险标的之保险单,常见于汽车车损险. ...

  7. C和C++算法完整教程专栏完整目录

    C和C++算法完整教程专栏完整目录 专栏说明如下 完整专栏目录如下 专栏说明如下 内容:C和C++算法完整教程 数量:680篇博文(2023年2月15日截止) 更新时间至:2023年2月15日(后续加 ...

  8. 提取了下刘汝佳推荐的题号...

    今天闲来没事上uva oj提取了下刘汝佳推荐的acm题号,原始数据如下: Volume 0. Getting Started    10055 - Hashmat the Brave Warrior ...

  9. 大数的菲波那契计算/Huge Fibonacci Numbers - ACM

    Huge Fibonacci Numbers 时间限制: 1 Sec   内存限制: 128 MB 题目描述 A Fibonacci sequence is calculated by adding ...

最新文章

  1. pandas实现众数和众数的频数
  2. 发现一篇超详细的ELK搭建
  3. 用 Python 画个生日蛋糕为朋友庆生
  4. Linux——多线程
  5. gcc-5.4.0 static dwarf2 compile
  6. Java代码中变量的特殊修饰符/修饰词/关键字
  7. 25. K 个一组翻转链表
  8. Visual Studio“Orcas”October 2006 CTP版下载
  9. 设计模式之禅--思维导图
  10. python txt转json_实战篇 | 用Python来找你喜欢的妹子(二)
  11. matlab 向前欧拉公式,向前欧拉公式在Matlab解微分方程初值解的问题
  12. php 将多个数组 相同的键重组,PHP – 合并两个类似于array_combine但具有重复键的数组...
  13. 2021双十一电商行业研究报告:重塑消费决策链条,内容种草成电商新标配
  14. httpcline转发_go http请求转发
  15. 面试准备每日五题:C++(四)——typedefdefine、指针常量、队列栈、地址赋值、C和C++结构体
  16. 多线程依次打印abcabc
  17. 若干小球碰撞的一种暴力解题法
  18. 8个免费、可商用的视频素材网站,一定要收藏
  19. 数据分析训练营-pandas
  20. web打印模板神器reportbro—汉化及中文字体配置(上)

热门文章

  1. wps linux 字体_WPS Office:Linux 上的 Microsoft Office 的免费替代品 | Linux 中国
  2. CSDN2013年度博客之星评选
  3. linux内核rop姿势详解,Linux内核ROP姿势详解(二)
  4. 二叉树 查找失败 asl_算法——二分搜索amp;折半查找
  5. parafac 分解_基于PARAFAC分解的大规模MU-MIMO稀疏信道估计
  6. MySql性能优化学习路线图
  7. 报错:Ticket expired while renewing credentials 原因:Hue 集成Kerberos 导致Kerberos Ticket Renewer 起不来
  8. Eclipse IDE的安装与配置
  9. String与字节数组转换
  10. 剑指offer面试题66. 构建乘积数组