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

Show all messages Hide all messages

yeah, this case is impossible :"> Dinh Quang Hiep (mg9h@yahoo.com) 16 Jun 2001 11:53
2
2
1

Good luck !

QH@
const
  maxN = 100;
  pred : array[1..3]of longint = (3,1,2);
  succ : array[1..3]of longint = (2,3,1);

var
  now,tar : array[0..maxN]of longint;
  ans,n : longint;

  procedure Move(v,whi : longint);
  var i,j,middle : longint;
  begin
    if whi=pred[now[v]] then middle:=succ[now[v]]
                        else middle:=pred[now[v]];
    for i:=v-1 downto 1 do
      if now[i]<>middle then Move(i,middle);
    ans:=ans+1;
    now[v]:=whi;
  end;
var i : integer;
begin
  read(n);
  for i:=1 to N do begin
    read(tar[i]);
    now[i]:=1;
  end;
  for i:=n downto 1 do
    if tar[i]<>now[i] then Move(i,tar[i]);
  writeln(ans);
end.
> 2
> 2
> 1
>
> Good luck !
>
> QH@

I think the answer is 3!
1
2              -->   2          -->       -->     1
3 empty empty        3 empty 1      3 2 1      3  2  empty

What wrong with the answer? Is my comprehesion wrong?
Re: Do you mean the answer of Chen Xiaoke 1 Feb 2002 19:25
> > 2
> > 2
> > 1
> >
> > Good luck !
> >
> > QH@
>
> I think the answer is 3!
> 1
> 2              -->   2          -->       -->     1
> 3 empty empty        3 empty 1      3 2 1      3  2  empty
>
> What wrong with the answer? Is my comprehesion wrong?
>


your comprehesion is wrong. because you don't use the optimal
agoriythm
Re: Do you mean the answer of Chen Xiaoke 1 Feb 2002 19:25
> > 2
> > 2
> > 1
> >
> > Good luck !
> >
> > QH@
>
> I think the answer is 3!
> 1
> 2              -->   2          -->       -->     1
> 3 empty empty        3 empty 1      3 2 1      3  2  empty
>
> What wrong with the answer? Is my comprehesion wrong?
>


your comprehesion is wrong. because you don't use the optimal
agoriythm