Golden Radio Base
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 717 Accepted Submission(s): 299
Problem Description
Golden ratio base (GRB) is a non-integer positional numeral system that uses the golden ratio (the irrational number (1+√5)/2 ≈ 1.61803399 symbolized by the Greek letter φ) as its base. It is sometimes referred to as base-φ, golden mean base, phi-base, or, phi-nary.
Any non-negative real number can be represented as a base-φ numeral using only the digits 0 and 1, and avoiding the digit sequence "11" – this is called a standard form. A base-φ numeral that includes the digit sequence "11" can always be rewritten in standard form, using the algebraic properties of the base φ — most notably that φ + 1 = φ 2 . For instance, 11(φ) = 100(φ). Despite using an irrational number base, when using standard form, all on-negative integers have a unique representation as a terminating (finite) base-φ expansion. The set of numbers which possess a finite base-φ representation is the ring Z[1 + √5/2]; it plays the same role in this numeral systems as dyadic rationals play in binary numbers, providing a possibility to multiply.
Other numbers have standard representations in base-φ, with rational numbers having recurring representations. These representations are unique, except that numbers (mentioned above) with a terminating expansion also have a non-terminating expansion, as they do in base-10; for example, 1=0.99999….
Coach MMM, an Computer Science Professor who is also addicted to Mathematics, is extremely interested in GRB and now ask you for help to write a converter which, given an integer N in base-10, outputs its corresponding form in base-φ.
Any non-negative real number can be represented as a base-φ numeral using only the digits 0 and 1, and avoiding the digit sequence "11" – this is called a standard form. A base-φ numeral that includes the digit sequence "11" can always be rewritten in standard form, using the algebraic properties of the base φ — most notably that φ + 1 = φ 2 . For instance, 11(φ) = 100(φ). Despite using an irrational number base, when using standard form, all on-negative integers have a unique representation as a terminating (finite) base-φ expansion. The set of numbers which possess a finite base-φ representation is the ring Z[1 + √5/2]; it plays the same role in this numeral systems as dyadic rationals play in binary numbers, providing a possibility to multiply.
Other numbers have standard representations in base-φ, with rational numbers having recurring representations. These representations are unique, except that numbers (mentioned above) with a terminating expansion also have a non-terminating expansion, as they do in base-10; for example, 1=0.99999….
Coach MMM, an Computer Science Professor who is also addicted to Mathematics, is extremely interested in GRB and now ask you for help to write a converter which, given an integer N in base-10, outputs its corresponding form in base-φ.
Input
There are multiple test cases. Each line of the input consists of one positive integer which is not larger than 10^9. The number of test cases is less than 10000. Input is terminated by end-of-file.
Output
For each test case, output the required answer in a single line. Note that trailing 0s after the decimal point should be wiped. Please see the samples for more details.
Sample Input
1 2 3 6 10
Sample Output
1 10.01 100.01 1010.0001 10100.0101Hint
Source
这题题目意思完全没看懂。看过题解之后总结为,根据给出的两条规则,将数N换算成X进制,换算规则就是,如果出现连续的11就变成100,这是题目对于第一条规则的解释,φ^(n-1)+φ^(n-2)=φ^n;就是num[n-1]>0并且num[n-2]>0时,num[n]加一,那两个减1,这样子是成立的,但是可以更加优化,就是直接加减min(num[n-1],num[n-2])。第二条规则针对的是将数N拆分。2*φ^n=φ^(n+1)+φ^(n-2).两份num[n]可以拆成一份num[n+1]和num[n-2],所以同样的,更加优化一下就是拆出了num[n]/2份。留下的num[n]就变成了num[n]%2;
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue>
using namespace std;
int main()
{
long long n;
while(scanf("%lld",&n)!=EOF)
{
long long num[200];
memset(num,0,sizeof(num));
num[50] = n;
int flag = 1;
while(flag)
{
flag = 0;
for(int i=0;i<100;i++)
{
if(num[i]&&num[i+1])
{
long long tmp = min(num[i],num[i+1]);
num[i+2] += tmp;
num[i+1] -=tmp;
num[i] -= tmp;
flag = 1;
}
}
for(int i = 2;i<100;i++)
{
if(num[i]>1)
{
long long k = num[i]/2;
num[i+1] += k;
num[i-2] += k;
num[i] %= 2;
flag = 1;
}
}
}
long long st ,ed;
for(int i=0;i<100;i++)
if(num[i]!=0)
{
st = i;
break;
}
for(int i=199;i>=0;i--)
if(num[i]!=0)
{
ed = i;
break;
}
for(int i=ed;i>=st;i--)
{
if(i==49)printf(".");
printf("%lld",num[i]);
}
printf("\n");
}
return 0;
}