HDU - 4814 Golden Radio Base (长春赛区B题)

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-φ.
 

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.0101

Hint

题意:将一个10进制的数转化为题目要求的进制

思路:按照题目给出的两个方程,分别将两式都乘以φ^(n-2)

得到: φ^(n-1)+φ^(n-2)=φ^n;2*φ^n=φ^(n+1)+φ^(n-2),剩下的就是跟着模拟了,

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
const int MAXN = 200;

int a[MAXN];
int n;

int main() {
	while (scanf("%d", &n) != EOF) {
		memset(a, 0, sizeof(a));
		a[50] = n;
		int flag = 1;
		while (flag) {
			flag = 0;
			for (int i = 0; i < 100; i++) 
				if (a[i] && a[i+1]) {
					int Min = min(a[i], a[i+1]);
					a[i+2] += Min;
					a[i] -= Min;
					a[i+1] -= Min;
					flag = 1;
				}

			for (int i = 2; i < 100; i++) 
				if (a[i] > 1) {
					a[i-2] += a[i]/2;
					a[i+1] += a[i]/2;
					a[i] %= 2;
					flag = 1;
				}
		}
		int st,ed;
		for (int i = 100; i >= 0; i--)
			if (a[i]) {
				st = i;
				break;
			}
		for (int i = 0; i < 100; i++) 
			if (a[i]) {
				ed = i;
				break;
			}
		for (int i = st; i >= ed; i--) {
			if (i == 49)
				printf(".");
			printf("%d", a[i]);
		}
		printf("\n");
	}
	return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值