Cod sursa(job #1047309)

Utilizator Barcau_EmanuelBarcau Emanuel Barcau_Emanuel Data 4 decembrie 2013 10:54:13
Problema Castel Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include<fstream>
using namespace std;
ifstream f("castel.in");
ofstream g("castel.out");
int n,m,i,j,k,l,o,a[151][151],c,nr,x,y,xy;
bool b[151][151],d[22501];


int get(int x,int y)
{
    return m*(x-1)+y;
}

int ver(int x,int y)
{
    if(b[x-1][y]==1||b[x+1][y]==1||b[x][y-1]==1||b[x][y+1]==1) return 1;
    return 0;
}

void lee()
{
    bool ok;
    ok=1;
   while(ok==1)
   {
       ok=0;
       for(i=1;i<=n;i++)
       for(j=1;j<=m;j++)
       {
         if(ver(i,j)==1&&d[a[i][j]]==1&&b[i][j]==0)
         {
             b[i][j]=1;
             d[get(i,j)]=1;
             nr++;
             ok=1;
         }
       }
   }
}

int main()
{
 f>>n>>m>>c;
 for(i=1;i<=n;i++)
 for(j=1;j<=m;j++)
 {
     f>>a[i][j];
     xy++;
     if(xy==c) x=i,y=j;
 }
 nr++;
 d[a[x][y]]=1;
 b[x][y]=1;

 lee();

 g<<nr;

 return 0;
}