HDOJ 4814 Golden Radio Base

Source: Internet
Author: User

HDOJ 4814 Golden Radio Base


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.01100000011010.0001101000000101Hint 
 <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink">
  
Authorization + PC9wPgo8cD48YnI + cda-vcd4kpha + PHByZSBjbGFzcz0 = "brush: java;"> # include
  
   
# Include
   
    
# Include
    
     
# Include 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 ;}
    
   
  
 



Related Article

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.