HDOJ 4814 Golden Radio Base

利用题目中给出的公式和hint可以得到两个有用的公式:

phi^(n) = phi^(n-1)+phi^(n-2)

2*(phi^n) = phi^(n+1)+phi^(n-2)

可以计算出phi^100远大于10^9,所以推测最后得到的phi进制的数整数和小数部分应该不会超过100位,事实表明,50位就能过。

所以最终变成了简单的模拟。

Golden Radio Base

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 363    Accepted Submission(s): 165

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

2013 Asia Regional Changchun

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int base=100;

int n;
int wei[220];

int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        memset(wei,0,sizeof(wei));
        wei[base]=n;

        while(true)
        {
            bool flag=false;
            for(int i=0;i<200;i++)
            {
                if(wei[i]>1)
                {
                    int t=wei[i];
                    wei[i]=t%2;
                    wei[i+1]+=t/2;
                    wei[i-2]+=t/2;
                    flag=true;
                }
            }
            for(int i=0;i<200;i++)
            {
                if(wei[i]&&wei[i+1])
                {
                    int t=min(wei[i],wei[i+1]);
                    wei[i]-=t; wei[i+1]-=t;
                    wei[i+2]+=t;
                    flag=true;
                }
            }
            if(flag==false) break;
        }
        int st=-1,ed=-1;
        for(int i=0;i<202;i++)
            if(wei[i]) { st=i; break; }
        for(int i=202;i>=0;i--)
            if(wei[i]) { ed=i; break; }
        for(int i=ed;i>=st;i--)
        {
            printf("%d",wei[i]);
            if(i==base&&st!=i) putchar('.');
        }
        putchar(10);
    }
    return 0;
}
时间: 2024-10-14 00:59:54

HDOJ 4814 Golden Radio Base的相关文章

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

最小二乘法又叫做最小平方法,是一种数学优化技术.它通过最小化误差的平方和寻找数据的最佳函数匹配. 通常情况下最小二乘法用于求回归问题.以简单的线性最小二乘为例,二维平面上给定个点的坐标,确定一条直线, 要求大致符合这个点的走向. 我们可以设这条直线的方程为,那么就要使在处的函数值与给定的值相 差达到最小,也就是说,要确定的值,使得 最小.根据这种方法求的值就是典型的最小二乘法. 可以看出是的一个二元函数,要求的最小值,那么求偏导,有 进一步得到 然后联立两式可以解出,如果方程数比较多,我们可以用

HDU 4814 Golden Radio Base 小模拟

链接:http://acm.hdu.edu.cn/showproblem.php?pid=4814 题意:黄金比例切割点是,如今要求把一个10进制的的数转化成一个phi进制的数,而且不能出现'11'的情况. 思路:因为题目中给出了两个式子,题目就变成了一道简单的模拟题了.因为整个phi进制的数最多仅仅有200,而数据中最多仅仅有100位,所以从aa[50]=tot 開始模拟就可以. 代码: #include<iostream> #include<cstdio> #include&l

HDU 4814 Golden Radio Base 模拟

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4814 题目大意: 把一个正整数表示为φ进制, φ = (1+√5)/2 . 且已知: 1. φ + 1 = φ 2 ,所以有11(φ) = 100(φ),且要求11要转变为100 2. 2 * φ 2  = φ3 + 1 . 解题思路: 观察发现,2 = 10.01.所以对于一个数N,能够从N/2 推导得到,是一个模拟的过程.我比赛的时候居然用了高速幂... 代码: #include<cstdio>

HDU 4814 Golden Radio Base

很显然是个进制转换的题,根据题意有a^2 = a + 1  -> a^n = a^(n-1) + a^(n-2),这样就能消除两个连续1. 另,a^3 = a^2 + 1 = 2*a+2 = 2*(a+1)  =  2*a.这样就可以将悉数转化为01. 10^9大约是2^30,所以总长度不超高150,直接模拟就好了. #include <algorithm> #include <iostream> #include <cstring> #include <c

ACM学习历程——HDU4814 Golden Radio Base(数学递推) (12年成都区域赛)

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 b

hdoj 3820 Golden Eggs 【最小割+拆点】

题目:hdoj 3820 Golden Eggs 题意:给出一个矩阵,然后当前有三种选择,放一个金蛋,放一个银蛋,或者不放,然后给出每个格子放金蛋或者银蛋的得分,如果金蛋相邻的话每个得分要减掉cost1,银蛋相邻的话每个减去cost2得分,问最大得分多少? 分析:做这个题目推荐先做hdoj 1659 ,3657点击打开链接 ,这个题目相当于前两个的融合在加点变化. 首先我们发现和前两个题目一样要求不能相邻,否则要减去一定的值,那么我们可以确定同样要用当前点的行列和的奇偶性建图. 那么我们可以按照

hdoj 3820 Golden Eggs 【双二分图构造最小割模型】

Golden Eggs Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 505    Accepted Submission(s): 284 Problem Description There is a grid with N rows and M columns. In each cell you can choose to put

2015.10.27 2013---长春

这场做了5题 呜呜呜--- 这场老是读错题,,,还读不懂题,,, 可以滚了--- A - Hard Code 签到 B - Golden Radio Base 进制的转换---读好久读不懂题--- C wtw 写的 D 读好久读不懂题--- E F syh发现是白薯模板题-- G wtw 用哈希,线段树搞的-- 还是不懂他怎么搞的 先用的模是1e9+7,,,wa了--- 后来用了这个----998244353 就过了-- J 最开始还以为是水题----sad--- 后来看了题解做的--- htt

HDU4814——数学,模拟进制转换

本题围绕:数学公式模拟进制转换 HDU4814 Golden Radio Base 题目描述 将一个十进制的非负整数转换成E(黄金分割数)进制的数 输入 不大于10^9的非负整数,处理到文件尾 输出 转换成的E进制数(可能含有小数) 样例输入 1 2 3 6 10 样例输出 1 10.01 100.01 1010.0001 10100.0101 题目分析 对于本题,要注意的点有:首先对于一个十进制的正数,我们是可以严格转换成一个E(黄金分割数)进制的数的,而不是涉及到约等于,例如10-base的