luogu#P3424. [POI2005] SUM-Fibonacci Sums
[POI2005] SUM-Fibonacci Sums
题目描述
Fibonacci numbers are an integer sequence defined in the following way: , , (for ). The first few numbers in this sequence are: ().
The great computer scientist Byteazar is constructing an unusual computer, in which numbers are represented in Fibonacci system i.e. a bit string denotes the number $b_1\cdot Fib_1+b_2\cdot Fib_2+\cdots+b_n\cdot Fib_n$. (Note that we do not use .) Unfortunately, such a representation is ambiguous i.e. the same number can have different representations. The number , for instance, can be written as: , or . For this very reason, Byteazar has limited himself to only using representations satisfying the following conditions:
if , then , i.e. the representation of a number does not contain leading zeros.
if , then (for ), i.e. the representation of a number does not contain two (or more) consecutive ones.
The construction of the computer has proved more demanding than Byteazar supposed. He has difficulties implementing addition. Help him!
TaskWrite a programme which:
reads from the standard input the representations of two positive integers,calculates and writes to the standard output the representation of their sum.
输入格式
The input contains the Fibonacci representations (satisfying the aforementioned conditions) of two positive integers and - one in the first, the other in the second line. Each of these representations is in the form of a sequence of non-negative integers, separated by single spaces. The first number in the line denotes the length of the representation , . It is followed by zeros and/or ones.
输出格式
In the first and only line of the output your programme should write the Fibonacci representation (satisfying the aforementioned conditions) of the sum . The representation should be in the form of a sequence of non-negative integers, separated by single spaces, as it has been described in the Input section. The first number in the line denotes the length of the representation , . It is followed by zeros and/or ones.
题目大意
斐波那契数是一个这样定义的整数:,, ,前几个数是这样的
伟大的计算机学家 正在做一个非凡的计算机,其中的数由斐波那契表示!
如一个数列 表示数字 $F(1) \times b_1+b_2 \times F(2)+ \ldots +b_n \times F(n)$(不使用 )。
不幸的是,这样的表示并不明确,即相同的数字可以有不同的表示。比如 可以表示为 , 或 ,于是 加了一个限制:
- 如果 ,那么,即数字的表示不包含前导零。
- 如果 ,那么 ,即数字的表示不包含两个(或多个)连续的数字。
这个计算机的建设比 所认为的要难,现在请你来帮帮他~。
你需要写一个程序:
读取两个正整数的表示,计算并向标准输出写入其和的表示。
输入格式
输入的第一行先是一个正整数,为 的斐波那契表示的长度,接下来的序列是 的斐波那契表示。
第二行的第一个数字也是一个正整数,为 的斐波那契表示的长度,接下来的序列是 的斐波那契表示。
输出格式
输出只有一行程序,应写入 的和的斐波纳契表示(满足上述条件),同样是先输出一个正整数 ,表示 的和的斐波纳契表示的长度,然后再输出 的和的斐波那契表示。
。
感谢@codesonic 提供的翻译
4 0 1 0 1
5 0 1 0 0 1
6 1 0 1 0 0 1