HDU 4814 Golden Radio Base(2013 ACM/ICPC 长春赛区现场赛)

Golden Radio Base

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1219    Accepted Submission(s): 494


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

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
 

Source
 

Recommend
liuyiding

题意:
给你一个数字让你把他转化成无理数进制的形式并且只用01表示(同时不能出现相邻数字都是1)

思路:
这一题其他大佬的博客我第一眼直接看不懂,后来自己悟出来了,决定自己写清楚。
首先我的第一感觉就是这题的结果不是最终那个数,但是显然不是的。比如这题的10.01为什么是2很好懂的,按照进制转换的规则,是不是 φ+φ^-2,这里这个数就是等于2。我们将数组的第50个元素首先设置为n,然后向两边扩散。


代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<queue>
using namespace std;

const int MAXN = 205;

int main()
{
    int a[MAXN],n,bas=100,flag;
    while(scanf("%d",&n)!=EOF)
    {
        memset(a,0,sizeof(a));
        a[50] = n,flag = 1;
        while(flag)
        {
            flag = 0;
            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;
                }
            for(int i = 0; i<100;i++)
                if(a[i]&&a[i+1])
                {
                    int tmp = min(a[i],a[i+1]);
                    a[i+2]+=tmp;
                    a[i]-=tmp;
                    a[i+1]-=tmp;
                    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、付费专栏及课程。

余额充值