What can be done to code this dynamically? How to fix the design flaw here?
-
Here is the problem statement: https://www.hackerrank.com/contests/oct13/challenges/chocolate-feast def wrapper(): testcases=input() for i in range(testcases): a=list(map(lambda x:int(x), raw_input().split())) choco=a[0]/a[1] last=a[2] test(choco, last) def test(choco, last): p=choco+1 if choco==last: printer(p) elif choco<last: printer(p-1) else: test(choco-last, last)# design isn't right, it is printing 2 for 6 6 2 i.e, not 3+2 to give 5 but just 2. Need to find some way to add dynamically! def printer(x): print x if __name__=='__main__': wrapper() 2) Secondly, in dynamic programming I'm very poor at designing the code. As you can see in the above solution. How can I overcome this?
-
Answer:
This problem can be solved like this for T in xrange(int(raw_input())): N, C, M = map(int, raw_input().split()) maxChocs = N // C result = maxChocs while maxChocs >= M: temp = maxChocs // M result += temp maxChocs %= M maxChocs += temp print result
Sakthipriyan Vairamani at Quora Visit the source
Related Q & A:
- How can I get the value of dynamically created input?Best solution by Stack Overflow
- How can I change iOS splash screen dynamically?Best solution by appcoda.com
- What can be done if a prospective employer cannot verify one of my past jobs in a employment background check?Best solution by Yahoo! Answers
- What can be done to save polar bears?Best solution by Yahoo! Answers
- What are professional jobs that can be done at home?Best solution by eHow old
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.