Pagini recente » Cod sursa (job #2774322) | Cod sursa (job #2349184) | Cod sursa (job #3195504) | Cod sursa (job #2871378) | Cod sursa (job #614572)
Cod sursa(job #614572)
#include<stdio.h>
long n,m,l,i,t2,j,a[200][200],b[200][200],c,d,e,t,ok,u,max,k,l3;
char ch[200][200];
int main()
{
freopen("rj.in","r",stdin);
freopen("rj.out","w",stdout);
scanf("%ld %ld\n",&n,&m);
for (i=1;i<=n;i++)
gets(ch[i]);
for (i=1;i<=n;i++)
for (j=0;j<=m-1;j++)
{
if (ch[i][j]=='X')
a[i][j+1]=1;
b[i][j+1]=a[i][j+1];
if (ch[i][j]=='R')
{
l=i;
t2=j+1;
}
if(ch[i][j]=='J')
{
c=i;
d=j+1;
}
}
a[l][t2]=2;
b[c][d]=2;
u=1;
while (ok==0)
{
u++;
ok=1;
for (i=1;i<=n;i++)
for (j=1;j<=m;j++)
if (a[i][j]==u)
{
if (a[i][j+1]==0)
{
ok=0;
a[i][j+1]=u+1;
}
if (a[i][j-1]==0)
{
ok=0;
a[i][j-1]=u+1;
}
if (a[i-1][j]==0)
{
ok=0;
a[i-1][j]=u+1;
}
if (a[i-1][j-1]==0)
{
ok=0;
a[i-1][j-1]=u+1;
}
if (a[i-1][j+1]==0)
{
ok=0;
a[i-1][j+1]=u+1;
}
if (a[i+1][j]==0)
{
ok=0;
a[i+1][j]=u+1;
}
if (a[i+1][j+1]==0)
{
ok=0;
a[i+1][j+1]=u+1;
}
if (a[i+1][j-1]==0)
{
ok=0;
a[i+1][j-1]=u+1;
}
}
if (ok==1)
break;
ok=1;
for (i=1;i<=n;i++)
for (j=1;j<=m;j++)
if (a[i][j]==0)
ok=0;
}
u=1;
ok=0;
while (ok==0)
{
u++;
ok=1;
for (i=1;i<=n;i++)
for (j=1;j<=m;j++)
if (b[i][j]==u)
{
if (b[i][j+1]==0)
{
ok=0;
b[i][j+1]=u+1;
}
if (b[i][j-1]==0)
{
ok=0;
b[i][j-1]=u+1;
}
if (b[i-1][j]==0)
{
ok=0;
b[i-1][j]=u+1;
}
if (b[i-1][j-1]==0)
{
ok=0;
b[i-1][j-1]=u+1;
}
if (b[i-1][j+1]==0)
{
ok=0;
b[i-1][j+1]=u+1;
}
if (b[i+1][j]==0)
{
ok=0;
b[i+1][j]=u+1;
}
if (b[i+1][j+1]==0)
{
ok=0;
b[i+1][j+1]=u+1;
}
if (b[i+1][j-1]==0)
{
ok=0;
b[i+1][j-1]=u+1;
}
}
if (ok==1)
break;
ok=1;
for (i=1;i<=n;i++)
for (j=1;j<=m;j++)
if (b[i][j]==0)
ok=0;
}
ok=0;
max=200000;
for (i=1;i<=n;i++)
for (j=1;j<=m;j++)
if (a[i][j]==b[i][j]&&a[i][j]>1)
if (max>a[i][j]-1)
{
max=a[i][j]-1;
k=i;
l3=j;
}
printf("%ld %ld %ld",max,k,l3);
}