Page 2 of 2

Re: 784 - Maze Exploration

Posted: Wed Sep 18, 2013 2:12 pm
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;
}


Re: 784 - Maze Exploration

Posted: Thu Sep 19, 2013 1:17 am
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.

Re: 784 - Maze Exploration

Posted: Thu Sep 19, 2013 9:19 am
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

Re: 784 - Maze Exploration

Posted: Sun Oct 27, 2013 5:04 pm
by dhruba07
GOT AC

Code: Select all

code removed

Re: 784 - Maze Exploration

Posted: Mon Oct 28, 2013 8:09 pm
by brianfry713
It looks like you figured it out.

784 - Maze Exploration WA

Posted: Thu Jan 23, 2014 9:58 pm
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:

Re: 784 - Maze Exploration WA

Posted: Fri Jan 24, 2014 9:53 pm
by brianfry713
Don't print a blank line at the start of the output.