Hello, i just made an AC with this problem and want to give few tips to others.
The main hardship in this problem is a horrible input/output example code, also those provided in this thread are mostly misguiding and wrong, so after a lot of pain and failure attempts by making some random corrections i eventually collected proper input and gathered enought data to finish the algorithm...
I will try to point out important things to pay attention to:
- since the range of values is undefined i decided to play it safe and used double type of variables,
This line generates correct output, just in case someone was wondering if maybe the presence of '\n' in the last line might be the reason of WA
- Instead of making one generic algorithm, try to exclude special cases like:
if (workers==1), this has two cases, one is when initial height divides by 2 down to 1, (all multipliers of 2) and when it doesnt (eg. 10) in which case i simply print : total_idlers=1; stack_height=initial_height+1;
there is no logic in last case but the debugger seems to like it that way ;D
Now, for the rest of the cases, you are looking for the "divider", when you have it you print the answer and this is where you fail miserably, then start hopelessly banging your head against the wall *,..,*
The reason is that some numbers have several 'working' dividers, and before you move on you have to verify it and if it wont work then for look for another
Basically the initial height and workers should divide exact amount of times by the 'divider' before reaching 1.
I hope that it will be helpfull and that i didint spoilered too much