ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1033. Labyrinth

help me
Posted by win 9 Feb 2003 05:43
#include<stdio.h>
#define x1 2
#define y1 1
long p_l=2,q[1330][3],n,l_s,x,y,p_f=1,wall=0;
char table[34][34];
f(long y,long x)
{
    q[p_l][x1]=x;
    q[p_l][y1]=y;
    p_l++;
    if(y<=n && x<=n-1 && x>=0 && y>=1)table[y][x]='o';
}
f_wall()
{

    while(p_l-p_f!=0)
    {
        x=q[p_f][x1];
        y=q[p_f][y1];
        p_f++;
        if(y>n || x>n-1 || x<0 || y<1)wall++;
        else
        {
            if(table[y-1][x]=='#')wall++;
            else if(table[y-1][x]!='o') f(y-1,x);

            if(table[y+1][x]=='#')wall++;
            else if(table[y+1][x]!='o')f(y+1,x);

            if(table[y][x-1]=='#')wall++;
            else if(table[y][x-1]!='o')f(y,x-1);

            if(table[y][x+1]=='#')wall++;
            else if(table[y][x+1]!='o')f(y,x+1);
        }
    }

}

main()
{
    FILE*fin=stdin
    FILE*fout=stdout
    long i,j,k;
    fscanf(fin,"%ld",&n);
    for(i=1;i<=n;i++)
    {
        fscanf(fin,"%s",table[i]);
    }
    q[1][x1]=n-1;
    q[1][y1]=n;
    if(table[n][n-1]=='#')wall+=0;
    else
    {
        table[n][n-1]='o';
        f_wall();
        wall-=2;
    }
    p_f=1;
    p_l=2;
    q[1][x1]=0;
    q[1][y1]=1;
    if(table[1][0]=='#')wall+=0;
    else
    {
        table[1][0]='o';
        f_wall();
        wall-=2;
    }
        wall*=9;
        fprintf(fout,"%ld",wall);
    fclose(fin);
    fclose(fout);
}