Pagini recente » Cod sursa (job #1332439) | Cod sursa (job #488631) | Cod sursa (job #1856208) | Cod sursa (job #1401087) | Cod sursa (job #1653731)
#include <cstdio>
using namespace std;
struct celula
{
int x;
int y;
};
int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1},n,m,curent,mat[155][155];
bool a[155][155],Q[23500];
int i,n1,sol,j;
celula b[23500];
bool verificare(int x,int y)
{
if(x>=1 && x<=n) if (y>=1 && y<=m && a[x][y]==0) return true;
return false;
}
void Lee()
{
bool OK=0;
for(i=1;i<=n1;i++) for(j=0;j<4;j++) if (Q[mat[b[i].x+dx[j]][b[i].y+dy[j]]] && verificare(b[i].x+dx[j],b[i].y+dy[j]))
{
sol++;
OK=1;
b[++n1].x=b[i].x+dx[j];
b[n1].y=b[i].y+dy[j];
a[b[n1].x][b[n1].y]=1;
Q[(b[n1].x-1)*m+b[n1].y]=1;
OK=1;
}
if(OK==1) Lee();
}
int main()
{
freopen("castel.in","r",stdin);
freopen("castel.out","w",stdout);
scanf("%d %d %d\n",&n,&m,&curent);
for(i=1;i<=n;i++) for(j=1;j<=m;j++) scanf("%d",&mat[i][j]);
b[1].x=(curent-1)/m+1;
b[1].y=(curent-1)%m+1;
n1=sol=1;
Q[curent]=1;
a[b[1].x][b[1].y]=1;
Lee();
printf("%d\n",sol);
}