Pagini recente » Cod sursa (job #2899536) | Cod sursa (job #2892604) | Cod sursa (job #289913) | Cod sursa (job #61981) | Cod sursa (job #2302566)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("rj.in");
ofstream fout("rj.out");
const int NMAX = 105;
int ma[NMAX][NMAX];
int cost[NMAX][NMAX][2];
struct WORKPLS
{
int f,s;
};
queue <WORKPLS> q;
int dx[9] = {0,-1,-1,0,1,1,1,0,-1};
int dy[9] = {0,0,1,1,1,0,-1,-1,-1};
int n,m;
bool interior(int x,int y)
{
if(x<=n and x>=1 and y<=m and y>=1) return 1;
return 0;
}
void lee(int x,int y,int rj)
{
q.push({x,y});
int coordx,coordy;
WORKPLS aux;
while(!q.empty())
{
aux = q.front();
q.pop();
for(int i=1;i<=8;i++)
{
coordx=aux.f+dx[i];
coordy=aux.s+dy[i];
if(interior(coordx,coordy)==1 and cost[coordx][coordy][rj]==0 and ma[coordx][coordy]==0)
{
cost[coordx][coordy][rj]=cost[aux.f][aux.s][rj]+1;
q.push({coordx,coordy});
}
}
}
}
char c[NMAX];
int main()
{
int xr,yr,xj,yj;
fin >> n >> m;
fin.get();
for(int i=1;i<=n;i++)
{
fin.getline(c,NMAX-4);
/// fout << c[0] << ' ' << c[1] << ' ' << c[2] << '\n';
for(int j=0;c[j]!='\n';j++)
{
if(c[j]=='X') ma[i][j+1]=1;
if(c[j]=='R')
{
xr=i;
yr=j+1;
}
if(c[j]=='J')
{
xj=i;
yj=j+1;
}
}
}
lee(xr,yr,1);
lee(xj,yj,2);
int minim=NMAX*NMAX;
int xrasp,yrasp;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(cost[i][j][1]!=0 and cost[i][j][1]==cost[i][j][2] and cost[i][j][1]<minim)
{
minim=cost[i][j][1];
xrasp=i;
yrasp=j;
}
}
}
fout << minim+1 << ' ' << xrasp << ' ' << yrasp;
return 0;
}