here is mycode :
Code: Select all
Accepted
Moderator: Board moderators
Code: Select all
Accepted
It seems the the series returns back to 0 1 1 ... for every value of n.tryit1 wrote:i got accepted by a lame method.
How did you find the period ? Found on net that period has to be less than 6*n. So generated upton 12*n and checked for repetition of first 10 numbers.
Anyone used floyd.
I haven't understood fully. Its a Fibonacci sequence. So, you cant find a sequence that you have mentioned. However, suppose the sequence is based on any other criteria. Then stl map (or a bst) is a solution to your problem, too. Of course if the number of states is small.tryit1 wrote:Yes it returns backs to 0 1 1 .. But that observation can mislead. From your AC solution looks like it doesn't in this case.
If we are given a sequence of numbers like 0,1,1,2,3,5,6,7,0,1,1,2,0,1,1,2,3,5,6,7,0,1,1,2
how do you find the period of this ? Any thing easier than KMP.
If the values were unique could we apply floyd cycle finding. Can we modify it for the above sequence ? i tried but when there are duplicate values it breaks.
I guess there should be some algorithm which finds the period of a repeating sequence much easily.