ACM/ICPC algorithm Training Math is very important-Fibonacci Lucas series (Hnnuoj 11589)

Source: Internet
Author: User

  

See this title, looks very tall on the appearance = =, in fact, this is also familiar with the things, first of all, the Fibonacci series of Popular Science.

    • Fibonacci sequence

Also known as the Golden section of the series , refers to such a series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 、......

mathematically , the Fibonacci sequence is defined as a recursive method: F (0) =0,f (1) =1,f (n) =f (n-1) +f (n-2) (n≥2,n∈n*)

In modern physics, quasi-crystal structure, chemistry and other fields, the Fibonacci sequence has a direct application, for this reason, the American Mathematical Council from 1963 published a "Fibonacci series quarterly" in the name of a mathematical magazine, used to specifically publish this research results.

    • Fibonacci Sequence and Golden Section-----(Examples of today)

It is interesting to note that this is an entirely natural number sequence, and the formula is expressed in irrational numbers . Moreover, when n tends to infinity, the ratio of the previous item to the latter becomes more and more close to the Golden Section 0.618. (or the latter is more and more close to the previous one, the fractional part is getting closer to the Golden segment 0.618, the ratio of the previous to the latter is getting closer to the Golden segment 0.618)

1÷1=1,1÷2=0.5,2÷3=0.666...,3÷5=0.6,5÷8=0.625,............,55÷89=0.617977, ..., ....... 144÷233=0.618025 ...    46368÷75025=0.6180339886 ... The closer to the back, the more close to the gold ratio.
    • Fibonacci Series-Some mathematical laws
sum of odd itemssum of even itemsSum of squares The following is the official entry question ~
    • Fibonacci Retracement-Lucas series
LucasSeries 1, 3, 4, 7, 11, 18 ..., also have the same nature as the Fibonacci sequence.    (We can call it Fibonacci-Lucas recursion: Starting with the third item, each item is equal to the first two and f (n) = f (n-1) + f (n-2). The two series also have a special connection (shown in the table below), F (n) *l (n) =f (2n), and L (n) =f (n-1) +f (n+1)
N 1 2 3 4 5 6 7 8 9 10 ...
Fibonacci sequence F (n) 1 1 2 3 5 8 13 21st 34 55 ...
Lucas sequence L (N) 1 3 4 7 11 18 29 47 76 123 ...
F (n) *l (n) 1 3 8 21st 55 144 377 987 2584 666T ...
There's an infinite number of similar sequences, which we call Fibonacci-Lucas Series。 such as 1,4,5,9,14,23 ..., because 1,4 beginning, can be remembered as f[1,4], Fibonacci sequence is f[1,1], the Lucas sequence is f[1,3], Fibonacci-Lucas series is f[a,b].
    • Another common property with the Fibonacci sequence: 
    • The absolute value of the difference between the square number of the middle term and the product of the previous and the next two items is a constant
Fibonacci sequence: |1*1-1*2|=|2*2-1*3|=|3*3-2*5|=|5*5-3*8|=|8*8-5*13|=...=1 Lucas series: |3*3-1*4|=|4*4-3*7|=...=5 f[1,4] Series: |4*4-1*5|= f[2,5] Series: |5*5-2*7|=11 f[2,7] Series: |7*7-2*9|=31
    • -----of gold characteristics (related to examples)
The Fibonacci sequence is 1 minimum, which is the ratio of the front and back. the fastest rate of close to gold, we call Gold FeaturesThe number of the Golden Signature 1 is only the Fibonacci sequence, which is the only sequence.    The golden character of the Lucas sequence is 5, and is the only sequence. The only number of the first two coprime is the Fibonacci sequence and the Lucas sequence. Application Examples: Test Instructions : roughly the given one of the Fibonacci retracement-Lucas series (the title is not stated, but this is actually the Fibonacci Polacillucas sequence), and then lets you find the initial Fibonacci retracement-Lucas sequence A1 and A2 values, And make the A2 as small as possible. I'm using the idea of mathematical law.
    • In the infinity of a Fibonacci retracement-Lucas sequence (recorded as item m), the term m-1 is bound to be infinitely close to the Golden section by dividing the M term 0.618---can calculate the fuzzy value of the second-to-last item (set to a)
    • And M is large enough, (m-1)/m>=0.618
    • Note: When the M value is large, (m-1)/M is close to 0.618, but the M value is too large, so 0.618*m the resulting fuzzy value will also have a large error, so you need to a++ until you find the most suitable first two
    • The detailed formula for the previous note is: sqrt (n) less than twice times.

1 //Fibonacci retracement-Lucas series2 //Memory 1100 k,time:234 Ms3#include <iostream>4#include <cstring>5#include <cstdio>6#include <cmath>7 using namespacestd;8 9 #defineINF 0x3f3f3f3fTen  One intm1,m2;//let the second smallest initial two items A  - //calculates the initial two items and refreshes the most suitable m1,m2 - voidComputeintAintBintt) the { -      while(t <= a && t >=1) -     { -b =A;  +A =T; -T = B-A; +     } A     if(M2 >b) at     { -M1 =A; -M2 =b; -     } - } -  in intMain () - { to     intT,n; +scanf"%d",&T); -  the      while(t--) *     { $         inta,t;Panax Notoginsengscanf"%d",&n); -A = (int)(0.618*n)-1;//the second-lowest fuzzy value the  +M1 = m2 =INF; A         inti =-1; the          while(A + (++i) <= n && i <= (int)2*SQRT (n))//The penultimate item is less than the last, and the number of times is less than 2*SQRT (n) +         { -Compute (a+i,n,n-a-i); $         } $  -printf"%d%d\n", m1,m2); -     } the  -     return 0;Wuyi}

The above code i <= (int) 2*sqrt (n) inequality is small, test data in these times can be over, if not added, it must be tle.

If you have more appropriate code can be written in the comments (⊙o⊙) Oh ~, the small part is too slag, no more clearly understand the idea =

fighting~

ACM/ICPC algorithm Training Math is very important-Fibonacci Lucas series (Hnnuoj 11589)

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.