1258 - Nowhere Money
Solution Description : Fibonacci number problem Example: Fibonacci number sequence: 1 2 3 5 8 13 21 ..... Input: n = 10 Check Fibonacci number greatest to smallest So, First take 21 which is greater than n , no need to calculate anything. then take 13 which is also greater than n, no need to calculate anything. take 8 which is less than n, So you find the slot 5 and slot value 8. and set n = n - 8 = 10 - 8 = 2 take 5 which is greater than n (2), no need to calculate anything. take 3 which is also greater than n(2), no need to calculate anything. take 2 which equal n (2) , So you find the slot 2 and slot value 2. ans set n = 2 - 2 = 0 if n = 0 then break the procedure. So, condition is if n<=fibNum[i] then store the slot number and slot value. ans set n = n - fibNum[i]. Here i from 90 to 1 First pre-generate first 90 Fibonacci number. then find the slot and slot value using the procedure which is given above. use unsigned long long for fibNum[] array. I got 20 times Presentation Error before AC. In output specification "The second line is a series of slot sizes (in descending order) separated by spaces" Input: 1 10 1000000 My Output: 1 1 1 # 10 5@2 8@2 # 1000000 29@25@23@11@9 832040@121393@46368@144@55 # Note: Here # represent the blank line("
"), and @ represent the Space(" ") But judge output is: 1 1@ 1@ # 10 5@2@ 8@2@ # 1000000 29@25@23@11@9@ 832040@121393@46368@144@55@ # Note: Here # represent the blank line("
"), and @ represent the Space(" ") |
||||||||||