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

Give me tests
Posted by Crestez Leonard 2 Nov 2002 00:44
This seems like a very simple problem, but I can't see what's wrong. Please give me some test data. Yeah, I know OOP is useless:)

#include <fstream.h>

#ifdef ONLINE_JUDGE
#define in cin
#define out cout
#else
ifstream in("test.in");
ofstream out("test.out");
#endif

#define MAX 50
#define WALL 0
#define SPACE 1
#define REACH 2
#define ENTER 3

class CLabyrinth
{public:
   int a[MAX][MAX],n;
   void ReadData();
   void Fill(int x,int y);
   void Print();
   int Walls();
 };

void CLabyrinth::ReadData()
{int i,j;
 char c[MAX];
 in>>n;
 for (i=0;i<n;i++) a[0][2+i]=a[2+1][0]=a[n+1][i]=a[i][n+1]=WALL;
 a[0][0]=a[0][1]=a[1][0]=a[n+1][n+1]=a[n][n+1]=a[n+1][n]=ENTER;
 for (i=1;i<=n;i++)
  {in>>c;
   for (j=1;j<=n;j++)
    {if (c[j-1]=='.') a[i][j]=SPACE;
     if (c[j-1]=='#') a[i][j]=WALL;
     }
   }
 }

void CLabyrinth::Fill(int x,int y)
{if (a[x][y]!=SPACE) return;
 a[x][y]=REACH;
 Fill(x-1,y);Fill(x+1,y);Fill(x,y-1);Fill(x,y+1);
 }

void CLabyrinth::Print()
{int i,j;
 for (i=0;i<=n+1;i++)
  {for (j=0;j<=n+1;j++)
    {if (a[i][j]==SPACE) out<<'X';
     if (a[i][j]==WALL) out<<'#';
     if (a[i][j]==REACH) out<<'.';
     if (a[i][j]==ENTER) out<<'E';
     }
   out<<'\n';
   }
 }

int border(int a,int b)
{return(((a==REACH)&&(b==WALL))||((a==WALL)&&(b==REACH)));
 }

int CLabyrinth::Walls()
{int i,j,s=0;
 for (i=1;i<=n;i++)
   for (j=0;j<=n;j++)
     s+=border(a[i][j],a[i][j+1])+border(a[j][i],a[j+1][i]);
 return(s);
 }

void main()
{CLabyrinth Lab;
 Lab.ReadData();
 Lab.Fill(1,1);
 Lab.Fill(Lab.n,Lab.n);
 out<<9*Lab.Walls()<<'\n';
 }