Mai intai trebuie sa te autentifici.
Cod sursa(job #2269299)
Utilizator | Data | 25 octombrie 2018 20:58:15 | |
---|---|---|---|
Problema | Rj | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 1.97 kb |
#include <queue>
#include <fstream>
using namespace std;
ifstream fin ("rj.in");
ofstream fout ("rj.out");
struct Casuta
{
int x, y;
};
int dx[]={-1, -1, -1, 0, 1, 1, 1, 0};
int dy[]={-1, 0, 1, 1, 1, 0, -1, -1};
int N, M;
void complet (int mat[101][101], int xi, int yi)
{
queue <Casuta> q;
q.push({xi, yi});
mat[xi][yi] = 1;
while (!q.empty())
{
int x, y;
Casuta poz = q.front();
for (int k = 0; k < 8; k++)
{
x = poz.x + dx[k];
y = poz.y + dy[k];
if (x >= 0 && x < N && y >= 0 && y < M)
if (mat[x][y] == 0)
{
mat[x][y] = mat[poz.x][poz.y] +1;
q.push ({x, y});
}
}
q.pop();
}
}
int R[101][101];
int J[101][101];
char S[101];
int main ()
{
int tmin = 101*101, lmin = 101, cmin = 101, rj, ri, jj, ji, inti, intj;
fin >> N >> M;
fin.get();
for (int i = 0; i < N; i++)
{
fin.getline(S, 101);
for (int j = 0; j < M; j++)
{
if (S[j] == 'R')
{
R[i][j] = 1;
ri = i;
rj = j;
}
else
if (S[j] == 'J')
{
J[i][j] = 1;
ji = i;
jj = j;
}
else
if (S[j] == 'X')
{
R[i][j] = -1;
J[i][j] = -1;
}
}
}
complet (R, ri, rj);
complet (J, ji, jj);
for (int i = 0; i < N; i++)
for (int j = 0; j < M; j++)
if (R[i][j] == J[i][j] && R[i][j] > 0)
{
if (R[i][j] < tmin)
{
tmin = R[i][j];
inti = i;
intj = j;
}
}
fout << tmin << ' ' << inti + 1<< ' ' << intj + 1;
return 0;
}