Cod sursa(job #227374)

Utilizator ada_sAda-Mihaela Solcan ada_s Data 4 decembrie 2008 12:06:18
Problema Barbar Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <stdio.h>
int dx[]=(-1, 0, 1,  0);
    dy[]=( 0, 1, 0, -1);
int main()
{
	freopen("barbar.in", "r", stdin);
	freopen("barbar.out", "w", stdout);
	scanf("%d%d", &r, &c);
	i=0;
	f=-1;
	for (i=1; i<r; i++)
	{
		h[i][0]='-1';
		h[i][c+1]='-1';
		for (j=1; j<c; j++)
		{
			scanf("%c", &aux);
			if (aux=='D')
			{
				h[i][j]=0;
				f++;
				qx[f]=i;
				qy[f]=i;
			}//if
			if (aux=='.')
				h[i][j]=-2;
			if (aux=='*')
				h[i][j]=-1;
			if (aux=='I')
			{
				xi=i;
				yi=i;
			}//if
			if (aux=='O')
			{
				xf=i;
				yf=i;
			}//if			
		}//for j
	}//for i
	bfs();
	return 0;
}//main

void bfs()
{
	while (i<f)
	{
		tx=qx[i];
		ty=qy[i];
		i++;
		for (i=0; i<4; i++)
		{
			xx=tx+dx[i];
			yy=ty+dy[i];
			if (h[xx][yy]==-2)
			{
				h[xx][yy]=h[tx][ty]+1;
				f++;
				qx[f]=xx;
				qy[f]=yy;
			}//if
		}//for i
	}//while
}//void