Advertisement
usrv

Codeforces 362 E

Jul 14th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. okay
  2. http://mathworld.wolfram.com/BinetsFibonacciNumberFormula.html
  3. ^ explicit formula for fibonacci
  4. so
  5. if you draw a pretty little tree diagram
  6. you know that after the first turn, it either goes to the left or the right
  7. and then you have 3 possible positions:
  8. middle, which goes left or right
  9. or left and right, which can either stay or go back to the middle
  10.  
  11. so then when it's left/right, it has a 1/2 chance of going back to the middle, while middle has 0
  12. so if you let p(n) be the probability of middle after n turns
  13. then p(n + 1) = 1/2 (1 - p(n))
  14. since p(n) is the # of middles, so therefore 1 - p(n) is the number of lefts + rights
  15. then after that you can rearrange to find that 2p(n+1) + p(n) = 1
  16. and since this is true for all n, then 2p(n) + 2p(n - 1) = 1
  17. so then you set these equal to each other and p(n) + p(n - 1) = 2p(n+1)
  18. which is like a pseudo fibonacci
  19. and you can guess that the explicit formula for p(n) is something close to c * x ^ n
  20. where c and x are constants
  21. so then you end up with the equation c * x ^ n + c * x ^ (n - 1) = 2 * c * x ^ (n + 1)
  22. and you can cancel and get the quadratic 2 x^2 - x - 1 = 0
  23. and this has roots 1 and -1/2
  24. so i stole some inspiration from the fibonacci formula and tried to put it in the form (1) ^ n - (-1/2) ^n
  25. and plugged in values of p(1) p(2) and p(3) to solve for the other constants
  26. and that got me the 2/3 and the 1-
  27. and you piece it all together and that's the formula
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement