ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1054. Tower of Hanoi

So Simple Move Back
Posted by Locomotive 17 Feb 2003 21:05
Hints:
-  Use 3variable which means first,too and last and
-  do for n downto 1 ...
-  use "1 shr i" to get 2^i..
-  eachtime just swap 2 of (from,temp or too)...

and...
  for i:=n downto 1 do begin
    if p[i]=temp then
      begin writeln(-1); exit; end
    else
      if p[i]=from then
        swap(temp,too)
      else begin
        inc(ans,(1 shl (i-1)));
        swap(from,temp);
      end;
  end;

For more information:
  aidin_n7@hotmail.com
Re: So Simple Move Back
Posted by PSV 30 Nov 2007 22:54
Yeah cool problem IMHO