Code: Select all
1 X X X
1 X X X
2 3 1 X
1 X 2 X
X X 3 4
-evan
Moderator: Board moderators
Code: Select all
1 X X X
1 X X X
2 3 1 X
1 X 2 X
X X 3 4
that is refered only for the last row, or for the other edges of the maze too?the exit point is always a cell in the last line of the maze
Code: Select all
cut -after AC
1) Not that I know of.Emilio wrote:Hello,
I have seen this post, and I have decided to make three questions
1) Are there some tricky inputs?
2) When in the problem specification saysthat is refered only for the last row, or for the other edges of the maze too?the exit point is always a cell in the last line of the maze
3) Why is my code wrong?
Thanks in advance!
Code: Select all
1
6 6
1 1 2 1 2 3
2 1 4 3 2 1
3 4 5 1 2 3
3 2 1 6 5 4
4 5 6 7 1 2
9 9 9 9 9 3
Code: Select all
1 7
6 0
Code: Select all
1 1
6 6
Code: Select all
if (next == tope && x == F)
Code: Select all
if (x == F)
Strange, I got AC without considering the above rule.Christian Schuster wrote:Hi there, just got it AC after several submissions. And yes, the last subsequence of the path must be complete, but I think the phrasedoesn't state this clearly enough.The path consists of subsequences obeying to the following rule: 1; 1,2; 1,2,3; 1,2,3,4; and so on.
Code: Select all
#include<stdio.h>
short height,width,maze[30][30],end=0,point;
void search(short level,short run,short y,short x)
{
short a,b,temp,temps;
if(y==height && run==1)
{
printf("%hd %hd\n%hd %hd\n",1,point,y,x);
end=1;
return;
}
if(level==1 && end==0)
{
for(a=1;a<=width && end==0;a++)
{
if(maze[1][a]==1)
{
temp=maze[1][a];
maze[1][a]=0;
point=a;
search(2,1,1,a);
maze[1][a]=temp;
}
}
}
else if(end==0)
{
a=y;
b=x-1;
if(maze[a][b]==run && end==0)
{
run++;
temp=0;
if(run==level+1)
{
level++;
run=1;
temp=1;
}
temps=maze[a][b];
maze[a][b]=0;
search(level,run,a,b);
maze[a][b]=temps;
if(temp==0)
run--;
else
{
level--;
run=level;
}
}
a=y+1;
b=x;
if(maze[a][b]==run && end==0)
{
run++;
temp=0;
if(run==level+1)
{
level++;
run=1;
temp=1;
}
temps=maze[a][b];
maze[a][b]=0;
search(level,run,a,b);
maze[a][b]=temps;
if(temp==0)
run--;
else
{
level--;
run=level;
}
}
a=y-1;
b=x;
if(maze[a][b]==run && end==0)
{
run++;
temp=0;
if(run==level+1)
{
level++;
run=1;
temp=1;
}
temps=maze[a][b];
maze[a][b]=0;
search(level,run,a,b);
maze[a][b]=temps;
if(temp==0)
run--;
else
{
level--;
run=level;
}
}
a=y;
b=x+1;
if(maze[a][b]==run && end==0)
{
run++;
temp=0;
if(run==level+1)
{
level++;
run=1;
temp=1;
}
temps=maze[a][b];
maze[a][b]=0;
search(level,run,a,b);
maze[a][b]=temps;
if(temp==0)
run--;
else
{
level--;
run=level;
}
}
}
}
int main()
{
short a,b,c,cases;
scanf("%hd",&cases);
for(c=0;c<cases;c++)
{
scanf("%hd %hd",&height,&width);
for(a=0;a<=height+1;a++)
{
if(a==0 || a==height+1)
for(b=0;b<=width;b++)
maze[a][b]=0;
else
{
maze[a][0]=0;
for(b=1;b<=width;b++)
scanf("%hd",&maze[a][b]);
}
maze[a][b]=0;
}
point=0;
end=0;
search(1,1,0,0);
if(c!=cases-1)
printf("\n");
}
return 0;
}