## 10116 - Robot Motion

All about problems in Volume 101. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Skywalker1982
New poster
Posts: 2
Joined: Thu Oct 24, 2002 10:47 am
Location: Paris

### 10116 - Robot Motion

i have a WA and i don't understand why. I think this problem is very simple but maybe i forgot a test...
anyone can help me ?

#include <stdio.h>

void recupere(int rows,int cols,int enter)
{
char c;
int i=0,j=0;
char tab[rows][cols][2];

int compteur=0;

i=0;
while (i<rows)
{
j=0;
while (j<cols)
{
c=getchar();
tab[i][j][0]=c;
tab[i][j][1]=-1;
j++;
}
c=getchar();
i++;
}

i=0;
j=enter-1;

while ((i>=0)&&(i<rows)&&(j>=0)&&(j<cols))
{
char temp=tab[i][j][1];
tab[i][j][1]=(char)compteur;
compteur++;
switch (tab[i][j][0])
{
case 'N':i--;
break;
case 'S':i++;
break;
case 'W':j--;
break;
case 'E':j++;
break;
}
if (temp!=-1)
{
if (temp==0)
printf("%d step(s) before a loop of %d step(s)\n",compteur-1,compteur-1);
else
printf("%d step(s) before a loop of %d step(s)\n",temp,compteur-temp-1);
return;
}
}
printf("%d step(s) to exit\n",compteur);

}

int main()
{
int rows,cols,enter;
while (1)
{
scanf("%d",&rows);
scanf("%d",&cols);
scanf("%d",&enter);
if ((rows==0)&&(cols==0)&&(enter==0))
return 0;

getchar();
recupere(rows,cols,enter);
}
}
@END_OF_SOURCE_CODE ;-)[/c]

ei01036
New poster
Posts: 12
Joined: Wed Jan 15, 2003 1:13 am
i'm having the same problem... if anyone knows anything helpful, please say so! thanks

Zyaad Jaunnoo
Experienced poster
Posts: 122
Joined: Tue Apr 16, 2002 10:07 am

### Just cannot get it AC!!!

I tried all the test cases you put... it works fine with my program but still I did not get AC!
Can you please post on new tricky test data?

Thanks in advance...

seadoo
New poster
Posts: 12
Joined: Mon Dec 15, 2003 6:16 pm
Rong, thank you very much for your test cases!

I had a bug and couldn't find it. It was discovered through your test cases...

The bug was: if a cycle started in the first robot position, it was discovered as a cycle starting at the second robot position

tan_Yui
Experienced poster
Posts: 155
Joined: Sat Jul 10, 2004 12:41 am
I got WA... too.
Please give me the output according to the following input,
and show me some special test case if you have.

Code: Select all

``````2 2 1
SS
EW
2 1 1
S
N
2 2 2
ES
NW
1 1 1
S
0 0 0
[EOF]
``````
Thank you.

Eduard
Experienced poster
Posts: 183
Joined: Fri Sep 26, 2003 2:54 pm
Location: Armenia,Yerevan
Here are answers for your tests.

Code: Select all

``````1 step(s) before a loop of 2 step(s)
0 step(s) before a loop of 2 step(s)
0 step(s) before a loop of 4 step(s)
1 step(s) to exit
``````
I don't think there are any special tests.
someone who like to solve informatic problems.
http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:29650

tan_Yui
Experienced poster
Posts: 155
Joined: Sat Jul 10, 2004 12:41 am
Eduard, thank you for your reply !
I had made a mistake in reading a problem sentence,
"The word "step" is always immediately followed by "(s)" whether or not the number before it is 1."
I had treated "1 step(s)" -> "1 step".

After read your reply, I could get AC.

Best regards.

mukeshtiwari
Learning poster
Posts: 63
Joined: Tue Mar 07, 2006 6:51 pm
Location: india

### 10116

hi friends i trying to solve 10116 robot motion but its giving WA....i test all the data availble on forum but still its giving WA kindly test my program againts some accepted program..plz....
here is my code...

#include<stdio.h>
#include<string.h>

main()
{

int b[100][100],c[100][100],i,j,m,n,k,u,v;
char a[100][100];
while( scanf("%d%d%d",&m,&n,&k) && ( m||n||k))
{
getchar();
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)

{
a[j]=getchar();
b[j]=1;
c[j]=0;
}
getchar();
}

k=k-1;
b[0][k]=0;//starting point
u=0,v=0;

for(i=1;;i++)
{

if(a[v][k]=='E')
{
k=k+1;
u=u+1;
if(k>=n)
{
if(u==1)
printf("%d step to exit\n",u);
else
printf("%d step(s) to exit\n",u);
break;
}
else
{
if(b[v][k]==0)//visited
{
if(c[v][k]==1)
printf("%d step before a loop of %d step(s)\n",c[v][k],u-c[v][k]);
else
printf("%d step(s) before a loop of %d step(s)\n",c[v][k],u-c[v][k]);
break;
}
else
{
b[v][k]=0;
c[v][k]=i;
}
}
}
else if(a[v][k]=='S')
{
v=v+1;
u=u+1;
if(v>=m)
{
if(u==1)
printf("%d step to exit\n",u);
else
printf("%d step(s) to exit\n",u);
break;
}
else
{
if(b[v][k]==0)//already visited initially
{
if(c[v][k]==1)
printf("%d step before a loop of %d step(s)\n",c[v][k],u-c[v][k]);
else
printf("%d step(s) before a loop of %d step(s)\n",c[v][k],u-c[v][k]);
break;
}
else
{
b[v][k]=0;
c[v][k]=i;
}
}
}
else if(a[v][k]=='W')
{
k=k-1;
u=u+1;
if(k<0)
{
if(u==1)
printf("%d step to exit\n",u);
else
printf("%d step(s) to exit\n",u);
break;
}
else
{
if(b[v][k]==0)
{
if(c[v][k]==1)
printf("%d step before a loop of %d step(s)\n",c[v][k],u-c[v][k]);
else
printf("%d step(s) before a loop of %d step(s)\n",c[v][k],u-c[v][k]);
break;
}
else
{
b[v][k]=0;
c[v][k]=i;
}
}
}

else if(a[v][k]=='N')
{
v=v-1;
u=u+1;
if(v<0)
{
if(u==1)
printf("%d step to exit\n",u);
else
printf("%d step(s) to exit\n",u);
break;
}
else
{
if(b[v][k]==0)
{
if(c[v][k]==1)
printf("%d step before a loop of %d step(s)\n",c[v][k],u-c[v][k]);
else
printf("%d step(s) before a loop of %d step(s)\n",c[v][k],u-c[v][k]);
break;
}
else
{
b[v][k]=0;
c[v][k]=i;
}
}
}
}//forloop

}//while
}//main

ALEXANDRIA_2
New poster
Posts: 10
Joined: Tue Nov 07, 2006 2:03 pm
Location: Jakarta
hi mukeshtiwari,
it said that:

Code: Select all

``````The word "step" is always immediately followed by "(s)" whether or not the number before it is 1.
``````
u should add "(s)" on all your print statement...
and maybe remove your comment statement...

Hope u get AC soon.
Impossible is nothing

mukeshtiwari
Learning poster
Posts: 63
Joined: Tue Mar 07, 2006 6:51 pm
Location: india
thnkx for reply .i was really helpless for this problem becoz could not figure out what is going wrong with this problems....thnkx again..

loghiyan
New poster
Posts: 6
Joined: Fri Dec 22, 2006 6:19 pm
REMOVED AFTER AC