Hdoj 4814 golden radio base

Source: Internet
Author: User


Two useful formulas can be obtained using the formula and hint given in the question:
Phi ^ (n) = Phi ^ (n-1) + Phi ^ (n-2)
2 * (PHI ^ n) = Phi ^ (n + 1) + Phi ^ (n-2)
It can be calculated that Phi ^ 100 is much greater than 10 ^ 9. Therefore, it is estimated that the number integer and decimal part of the final Phi hexadecimal number should not exceed 100 digits. It turns out that 50 digits can pass.
So it eventually becomes a simple simulation.

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 descriptiongolden 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 phi) as its base. it is sometimes referred to as base-Phi, 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-phi numeral that could des the digit sequence "11" can always be rewritten in standard form, using the algebraic properties of the base phi-most notably that Phi + 1 = Phi 2. for instance, 11 (PHI) = 100 (PHI ). despite using an irrational number base, when using standard form, all on-negative integers have a unique representation as a terminating (finite) Base-phi expansion. the set of numbers which possess a finite base-phi 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-Phi, with rational numbers having recurring representations. these representations are unique, counter t 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 platform sor 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-phi.
Inputthere 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.
Outputfor each test case, output the required answer in a single line. Note that trailing 0 s after the decimal point shocould be wiped. Please see the samples for more details.
Sample Input
123610
 
Sample output
110.01100.011010.000110100.0101Hint 
 
Source2013 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;}



Hdoj 4814 golden radio base

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.