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

late_riser
New poster
Posts: 3
Joined: Wed Sep 18, 2013 2:05 pm

Re: 784 - Maze Exploration

Post by late_riser »

Getting WA, donno why...

can someone check my code?

Thanks

Code: Select all

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

char str[35][85];
int train[100];
int index_i;

void Akromon(const int i, const int j){
    
    str[i][j]='#';

   
    if(i-1>=0&&str[i-1][j]==' ') {//printf("diving into:i-1 j\n");
            Akromon(i-1,j);}
    if(str[i-1][j+1]==' ') {//printf("diving into:i-1 j+1\n");
            Akromon(i-1,j+1);}
    if(i-1>=0&&j-1>=0&&str[i-1][j-1]==' ') {//printf("diving into:i-1 j-1\n");
            Akromon(i-1,j-1);}

    if(j-1>=0&&str[i][j-1]==' ') {//printf("diving into:i j-1\n");
            Akromon(i,j-1);}
    if(str[i][j+1]==' ') {//printf("diving into:i j+1\n");
            Akromon(i,j+1);}

    if(i+1<=index_i-1&&str[i+1][j]==' ') {//printf("diving into:i+1 j\n");
            Akromon(i+1,j);}
    if(i+1<=index_i-1&&str[i+1][j+1]==' ') {//printf("diving into:i+1 j+1\n");
            Akromon(i+1,j+1);}
    if(i+1<=index_i-1&&j-1>=0 && str[i+1][j-1]==' ') {//printf("diving into:i+1 j-1\n");
            Akromon(i+1,j-1);}
return;
}


int main(){

int T, t;

while(scanf("%d",&T)==1){

    //getchar();
    memset(train,0,sizeof(train));
    memset(str,'\0',sizeof(str));
    for(t=1;t<=T;t++){

        index_i=-1;

        do{
            index_i++;
            gets(&str[index_i][0]);
                train[index_i]=strlen(&str[index_i][0]);
    
        }while(str[index_i][0]!='_');
    
        for(int i=0; i<index_i;i++){
    
            for(int j=0;j<train[i];j++){
                if(str[i][j]=='*')
                        Akromon(i,j);
            }
        }


        for(int i=0; i<index_i;i++){

            for(int j=0;j<train[i];j++)
                printf("%c",str[i][j]);

        printf("\n");
        }

    
    }
}


return 0;
}

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 output text of a painted maze has the same format as that which has been read for that maze, including the separation lines.
Check input and AC output for thousands of problems on uDebug!
late_riser
New poster
Posts: 3
Joined: Wed Sep 18, 2013 2:05 pm

Re: 784 - Maze Exploration

Post by late_riser »

Hi brainfry713,

Thanks for your help.

Yes, the output format was incorrect, but I still was getting WA.
Actually my problem was, I checked UP-DOWN-LEFT-RIGHT and also the "corner sides". And this was the mistake.

After I removed checking the corners, I got AC.

Thanks again for your kind reply.

Sadi
dhruba07
New poster
Posts: 20
Joined: Tue May 21, 2013 9:02 pm
Location: BUET

Re: 784 - Maze Exploration

Post by dhruba07 »

GOT AC

Code: Select all

code removed
Last edited by dhruba07 on Tue Oct 29, 2013 9:18 am, edited 1 time in total.
Accept who you are :)
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 784 - Maze Exploration

Post by brianfry713 »

It looks like you figured it out.
Check input and AC output for thousands of problems on uDebug!
MauriWilde
New poster
Posts: 14
Joined: Sun Jan 20, 2013 1:58 am

784 - Maze Exploration WA

Post by MauriWilde »

Could somebody tell me why am I getting WA in this problem?

Code: Select all

#include <iostream>
#include <cstring>
#include <queue>

using namespace std;

char M[35][85];
int V[35];

int dx[]={-1,-1,-1,0,0,1,1,1};
int dy[]={-1,0,1,-1,1,-1,0,1};


void BFS(int n, int m)
{
    queue<int>X;
    queue<int>Y;
    X.push(n);
    Y.push(m);
    M[n][m] = '#';
    while (!X.empty() && !Y.empty())
    {
        n = X.front();
        m = Y.front();
        for (int i=0; i<8; i++)
        {
            if (n >= 0 && n <= 30 && m >= 0 && m <= 80 && isspace(M[n+dx[i]][m+dy[i]]))
            {
                X.push(n+dx[i]);
                Y.push(m+dy[i]);
                M[n+dx[i]][m+dy[i]] = '#';
            }
        }
        X.pop();
        Y.pop();
    }
}


int main()
{
    int n1;
    string s;
    cin >> n1;
    for (int tc=1; tc<=n1; tc++)
    {
        memset (M, 0, sizeof(M));
        int n = -1;
        while (getline(cin, s))
        {
            n++;
            V[n] = s.length();
            for (int i=0; i<s.length(); i++)
            {
                M[n][i] = s[i];
            }
            if (s[0] == '_')
                break;
        }
        for (int i=0; i<=n; i++)
        {
            for (int j=0; j<V[i]; j++)
            {
                if (M[i][j] == '*')
                {
                    BFS(i, j);
                }
            }
        }
        for (int i=0; i<=n; i++)
        {
            for (int j=0; j<V[i]; j++)
            {
                cout << M[i][j];
            }
            cout << endl;
        }
    }
    return 0;
}
I tried a lot of different test cases and it works for all of them... So I must be forgetting something. :cry: :cry:
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 784 - Maze Exploration WA

Post by brianfry713 »

Don't print a blank line at the start of the output.
Check input and AC output for thousands of problems on uDebug!
Post Reply

Return to “Volume 7 (700-799)”