10276

Hanoi Tower Troubles Again!
Type:
General
Diff:2.0

Tricks

You can solve this using a method like greedy. The rule of this game is very easy. You always try to put a ball in the left most possible peg. If you can not put a ball in the given number of peg then the last ball number is the result. i.e.  First try to put ball 1 on peg 1 then try to put the ball 2 in peg 1 if possible, otherwise try on peg 2. For the ball 3 try in peg 1 and so on. A interesting thing of this problem is, all the possible input have a finite number of balls. So you do not need to print �1 for any of the input !!!!!!!!!!!! believe me�. There was no line in my code like printf(�-1\n�); J And all the output fit in 32-bit integer.

Related Problems & Topics

 

If you have any advice, complements 

or proposal, please  Send mail to Author

Submit

 

1