Cod sursa(job #406051)

Utilizator daliutzzaBratu Dalia daliutzza Data 1 martie 2010 09:28:20
Problema Rj Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <fstream.h>
int dx[]={-1, 1, 0, 0, -1, 1, -1, 1}, dy[]={0, 0, -1, 1, -1, -1, 1, 1 }, a[101][101];
int main()
{ int i, j, n, m, x, y, cx[10000], cy[10000], xv, yv, p, u, ok, x1, y1, t=0;
char c;
ifstream f("1.in");
ofstream g("1.out");
f>>n>>m;
for (i=1;i<=n;i++)
	for (j=1;j<=m;j++) {f>>c;  if(c=='R') a[i][j]=2;
									 else if(c=='J') a[i][j]=2;
										  else if(c=='X') a[i][j]=0;
										      else a[i][j]=1;}
p=u=1;
cx[u]=1; 
cy[u]=1; 
a[1][1]=1;
while (p<=u&&ok==0)
	{
	x=cx[p]; 
	y=cy[p++];
	for (i=0; i<=7;i++){
	    xv=x+dx[i];
		yv=y+dy[i];
		if (xv<=n && xv>=1 && yv<=n && yv>=1 && a[xv][yv]==0||a[xv][yv]==2)
		{	t++;
			if(a[xv][yv]==2) ok=1; x1=xv; y1=yv;
			a[xv][yv]=a[x][y]+1;
			cx[++u]=xv; 
			cy[u]=yv;
		}
	}
}
g<<t/2<<" "<<x1<<" "<<y1;
f.close();
g.close();
return 0;
}