784 - Maze Exploration

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

Moderator: Board moderators

angga888
Experienced poster
Posts: 143
Joined: Sat Dec 21, 2002 11:41 am
Location: Indonesia

784 - Maze Exploration

Post by angga888 »

I am sure that my program is working correctly, but I still got WA :( . Any special or strange input?
What is the length of "_" character that indicates the end of one maze?
[/pascal]

Can anyone give me another creative input?

Regards
Angga888

Moinul(AUST)
New poster
Posts: 11
Joined: Tue Dec 10, 2002 11:40 am
Location: Dhaka, Bangaldesh
Contact:

Output Format

Post by Moinul(AUST) »

The problem is a simple one but getting WA. I think, my mistake lies in the output format.
Can anyone Help me specifying on how to format the output.

The problem suggests that, the output should be exactly like input along with the separation line. But, will there be any newline between two consecutive outputs? if the input contains some blank lines, will those blank lines be printed?

Any help will be appreciated... Thanks in advance.

Moinul
AUST, Bangladesh

UFP2161
A great helper
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm
Contact:

Post by UFP2161 »

Read each line of the file. Store in an array. When you hit a separator, flood-fill the array accordingly, print the array, including the separator line out, and repeat.

As long as the first character on the line is a '_', it is considered a separator.

Moinul(AUST)
New poster
Posts: 11
Joined: Tue Dec 10, 2002 11:40 am
Location: Dhaka, Bangaldesh
Contact:

Post by Moinul(AUST) »

Allthough I had the problem solved long ago... :)

Thanks to UFP2161 for respnsing to this query..
I hope, it will help others trying to sove 784

----------------------------------------------------------

Moinul,
Bangladesh

lky
New poster
Posts: 21
Joined: Fri Dec 05, 2003 5:59 pm
Contact:

784

Post by lky »

i think my program works for all sort of input...but still wa.....can anyone give me some critical inputs for this problem? i simply floodfill the places which is reachable from the * room....

program q784;
var a:array[1..40]of string;
n,i,j,k,l,x,y:integer;
procedure recur(s,t:integer);
var u,v:integer;
begin
a[s,t]:='#';
if (s>1)and(length(a[s-1])>=t)
then if (a[s-1,t]=' ')
then recur(s-1,t);
if (t>1)and(a[s,t-1]=' ')
then recur(s,t-1);
if (s<l-2)and(length(a[s+1])>=t)
then if (a[s+1,t]=' ')
then recur(s+1,t);
if (t<length(a[s]))and(a[s,t+1]=' ')
then recur(s,t+1)
end;
begin
readln(n);
for k:=1 to n do
begin
l:=1;
readln(a[l]);
while a[l][1]<>'-' do
begin
l:=l+1;
readln(a[l])
end;
for i:=1 to l-1 do
for j:=1 to length(a) do
if a[j]='*'
then begin
x:=i;
y:=j;
recur(x,y)
end;
for i:=1 to l do
begin
for j:=1 to length(a) do
write(a[j]);
writeln
end;
end
end.

pls help, ty in advance

Dejarik
New poster
Posts: 32
Joined: Sun Mar 07, 2004 1:23 pm
Location: Barcelona, SPAIN
Contact:

784 - Maze Exploration. Please look these inputs...

Post by Dejarik »

Hello! I'm becoming crazy trying to find why this simple problem are returning me Wrong Answer in all the implementations I can design to solve it. I decided to build a great input in order to submit it here to be checked by anyone who received Correct Answer in his implementation.

Thanks in advance!

Joan, SPAIN

Here is my input:

Code: Select all

4
AAAAAAAAA  
A   A   A
A * A   A
A   A   A
AAAAAAAAA
_________
BBBBB   BBBBB
B   B   B   B
B * B   B   B
B   B   B   B
BBBBB   BBBBB
_________
CCCCCCCCCCCCC
C   C   C   C
C * C   C   C
C   C   C   C
CC CCCCCCC CC
C   C   C   C
C           C
C   C   C   C
CC CCCCCCC CC
C   C   C   C
C   C   C   C
C   C   C   C
CCCCCCCCCCCCC
_____________
AXXXBXXXCXXXDXXXEXXXFXXXG   
X   X   X   X   X   X   X
X *     X   X           X
X   X   X   X   X   X   X
XXXXXX XXXXXXXXXXXXXXX XX
X   X   X   X   X   X   X
X   X                   X  
X   X   X   X   X   X   X 
HXXXIXXXJXXXKXXXLXXXMXXXX
_________________________
And that's the returned output with my executable:

Code: Select all

AAAAAAAAA  
A###A   A  
A###A   A  
A###A   A  
AAAAAAAAA  
_________
BBBBB   BBBBB
B###B   B   B
B###B   B   B
B###B   B   B
BBBBB   BBBBB
_________
CCCCCCCCCCCCC
C###C   C###C
C###C   C###C
C###C   C###C
CC#CCCCCCC#CC
C###C###C###C
C###########C
C###C###C###C
CC#CCCCCCC#CC
C###C   C###C
C###C   C###C
C###C   C###C
CCCCCCCCCCCCC
_____________
XXXXXXXXXXXXXXXXXXXXXXXXX   
X###X###X   X###X###X###X   
X#######X   X###########X   
X###X###X   X###X###X###X   
XXXXXX#XXXXXXXXXXXXXXX#XX   
X   X###X###X###X###X###X   
X   X###################X   
X   X###X###X###X###X###X   
XXXXXXXXXXXXXXXXXXXXXXXXX   
_________________________

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

post your code

Post by sohel »

Your output seems to be correct and matches with my AC code's output...
... may be you are not handling the input taking properly....
.. I am not a supporter of posting code over here but I think in this case you should...
.. why don't you post your code and may be errors can be detected..

utter
New poster
Posts: 1
Joined: Fri Jun 11, 2004 12:11 pm
Location: Russia, Novgorod the Great
Contact:

help me... please

Post by utter »

I am ashamed, :oops: but I can't solve this problem. I am trying to write the program on Pascal, but nothing is good. :(
But I must solve it on this two weeks, because I get this task in my university.
Help me... maybe you have the code of this task on Pascal or C++, please, mail me - utter@yandex.ru

nukeu666
New poster
Posts: 44
Joined: Sun Feb 13, 2005 1:13 am
Location: India
Contact:

784 PE why? (maze exploration)

Post by nukeu666 »

heres the io i get from the program, why is it PE?

Code: Select all

7
AAAAAAAAA 
A   A   A
A * A   A
A   A   A
AAAAAAAAA
_________
BBBBB   BBBBB
B   B   B   B
B * B   B   B
B   B   B   B
BBBBB   BBBBB
_________
CCCCCCCCCCCCC
C   C   C   C
C * C   C   C
C   C   C   C
CC CCCCCCC CC
C   C   C   C
C           C
C   C   C   C
CC CCCCCCC CC
C   C   C   C
C   C   C   C
C   C   C   C
CCCCCCCCCCCCC
_____________
AXXXBXXXCXXXDXXXEXXXFXXXG   
X   X   X   X   X   X   X
X *     X   X           X
X   X   X   X   X   X   X
XXXXXX XXXXXXXXXXXXXXX XX
X   X   X   X   X   X   X
X   X                   X 
X   X   X   X   X   X   X
HXXXIXXXJXXXKXXXLXXXMXXXX
_________________________
XXXXX
X  XX
X*XXX
X   X
X X X
X XX
X X
X X
XXX
__
XXX
X X
X*X
XX
____
AXXXBXXXCXXXDXXXEXXXFXXXG   
X   X   X   X   X   X   X
X *     X   X           X
X   X   X   X   X   X   X
XXXXXX XXXXXXXXXXXXXXX XX
X   X   X   X   X   X   X
X   X                   X 
X   X   X   X   X   X   X
HXXXIXXXJXXXKXXXLXXXMXXXX
_

Code: Select all


nuke@nukem ~
$ ./a.exe <in1 
AAAAAAAAA 
A###A   A 
A###A   A 
A###A   A 
AAAAAAAAA 
_________
BBBBB   BBBBB
B###B   B   B
B###B   B   B
B###B   B   B
BBBBB   BBBBB
_________
CCCCCCCCCCCCC
C###C   C###C
C###C   C###C
C###C   C###C
CC#CCCCCCC#CC
C###C###C###C
C###########C
C###C###C###C
CC#CCCCCCC#CC
C###C   C###C
C###C   C###C
C###C   C###C
CCCCCCCCCCCCC
_____________
AXXXBXXXCXXXDXXXEXXXFXXXG   
X###X###X   X###X###X###X   
X#######X   X###########X   
X###X###X   X###X###X###X   
XXXXXX#XXXXXXXXXXXXXXX#XX   
X   X###X###X###X###X###X   
X   X###################X   
X   X###X###X###X###X###X   
HXXXIXXXJXXXKXXXLXXXMXXXX   
_________________________
XXXXX
X##XX
X#XXX
X###X
X#X#X
X#XX 
X#X  
X#X  
XXX  
__
XXX
X#X
X#X
XX 
____
AXXXBXXXCXXXDXXXEXXXFXXXG   
X###X###X   X###X###X###X   
X#######X   X###########X   
X###X###X   X###X###X###X   
XXXXXX#XXXXXXXXXXXXXXX#XX   
X   X###X###X###X###X###X   
X   X###################X   
X   X###X###X###X###X###X   
HXXXIXXXJXXXKXXXLXXXMXXXX   
_

nuke@nukem ~
$ 
google

algoJo
New poster
Posts: 37
Joined: Sun Dec 17, 2006 9:02 am

Post by algoJo »

for your inputs my AC program gave:

OUTPUT

Code: Select all

##########
##########
##########
##########
##########
_________ 
##############
##############
##############
##############
##############
_________ 
##############
##############
##############
##############
##############
##############
##############
##############
##############
##############
##############
##############
##############
_____________ 
AXXXBXXXCXXXDXXXEXXXFXXXG    
X###X###X   X###X###X###X 
X#######X   X###########X 
X###X###X   X###X###X###X 
XXXXXX#XXXXXXXXXXXXXXX#XX 
X   X###X###X###X###X###X 
X   X###################X 
X   X###X###X###X###X###X 
HXXXIXXXJXXXKXXXLXXXMXXXX 
_________________________ 
XXXXX 
X##XX 
X#XXX 
X###X 
X#X#X 
X#XX 
X#X 
X#X 
XXX 
__ 
XXX 
X#X 
X#X 
XX 
____ 
AXXXBXXXCXXXDXXXEXXXFXXXG    
X###X###X   X###X###X###X 
X#######X   X###########X 
X###X###X   X###X###X###X 
XXXXXX#XXXXXXXXXXXXXXX#XX 
X   X###X###X###X###X###X 
X   X###################X 
X   X###X###X###X###X###X 
HXXXIXXXJXXXKXXXLXXXMXXXX 
_
---empty line----
hope it helps..

hamedv
Learning poster
Posts: 98
Joined: Mon May 07, 2007 8:30 am

Post by hamedv »

you most to replace this line
while a[l][1]<>'-' do
whith
while a[l][1]<>'_' do

Sabiha_Fancy
New poster
Posts: 24
Joined: Mon Jul 16, 2012 3:43 pm

Re: 784 - Maze Exploration

Post by Sabiha_Fancy »

I am getting WA for a long time.But unable to find error. If anyone help i will be glad. #include<stdio.h>
#include<stdlib.h>

char maze[100][100];

void floodFill(int start_row,int start_col);
int main()
{
int no_of_maze,i,j,start_row,start_col,k,flag;

scanf("%d",&no_of_maze);
fflush(stdin);
for(i=0; i<no_of_maze; ++i)
{
flag = 0;
start_row = -5;
start_col = -5;
for(j=0; ; ++j)
{
gets(maze[j]);
if(maze[j][0] == '_')
break;
if(start_row == -5 && start_col == -5)
{ for(k=0; maze[j][k]!='\0'; ++k)
{
if(maze[j][k] == '*')
{
start_row = j;
start_col = k;
flag = 1;
break;
}
}
}
}
if(flag == 1)
floodFill(start_row,start_col);
for(k=0; k<=j; ++k)
{
puts(maze[k]);
}
}
return 0;
}

void floodFill(int start_row,int start_col)
{
if(maze[start_row][start_col] == ' ' || maze[start_row][start_col] == '*')
{
maze[start_row][start_col] = '#';
floodFill(start_row,start_col-1);
floodFill(start_row,start_col+1);
floodFill(start_row-1,start_col);
floodFill(start_row+1,start_col);
}
else
return;
}
Fancy

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 784 - Maze Exploration

Post by brianfry713 »

Don't use fflush(stdin);
Check input and AC output for thousands of problems on uDebug!

Sabiha_Fancy
New poster
Posts: 24
Joined: Mon Jul 16, 2012 3:43 pm

Re: 784 - Maze Exploration

Post by Sabiha_Fancy »

Thank you for your reply. I got ac. But what is the problem with fflush(stdin)?
Fancy

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 784 - Maze Exploration

Post by brianfry713 »

The behavior of fflush(stdin) is undefined for the C standard.
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 7 (700-799)”