ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1054. Tower of Hanoi

why WA? Is there any edge case I haven't covered?
Posted by AlainDelon 11 Oct 2007 19:01
c++ code as below
===================

#include <cstdio>
#include <iostream>

#define MAX_NUM 31

using namespace std;

int g_Dseq[MAX_NUM] = {1};
int g_Dtargseq[MAX_NUM];
int g_count = 0;
int N = 1;

int g_done = 0;

void movedisk(int n, int dsrc, int ddesc);
void hanoi_proc(int n,int dsrc, int daid, int ddesc);
int isdone();

void main()
{

int i=0;

cin >> N;

if(N <1 || N > 31)
{
cout<<-1;

}else
{

for(i=0;i<N;++i)
{
cin>> g_Dtargseq[i];
g_Dseq[i] = 1;

}

hanoi_proc(N, 1, 3, 2);

if(g_done ==0)
cout<<-1;

}

}

int isdone()
{
for(int i=0;i<N;++i)
{
if(g_Dseq[i] != g_Dtargseq[i]) return 0;
}

return 1;
}

void movedisk(int n, int dsrc, int ddesc)
{

g_Dseq[n-1] = ddesc;
++g_count;

if(g_done ==0 && isdone() == 1)
{
cout<<g_count;
g_done = 1;
}
}

void hanoi_proc(int n,int dsrc, int daid, int ddesc)
{

if(n == 1)
{
movedisk(n, dsrc, ddesc);

}else
{
hanoi_proc(n-1, dsrc, ddesc, daid);

movedisk(n, dsrc, ddesc);

hanoi_proc(n-1, daid, dsrc, ddesc);
}
}

=============================