Pagini recente » Cod sursa (job #2670681) | Cod sursa (job #895107) | Cod sursa (job #2621613) | Cod sursa (job #2908977) | Cod sursa (job #2206909)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("rj.in");
ofstream fout("rj.out");
const int NMAX = 100, N = 10005;
struct st{char rj; int t;} a[NMAX + 5][NMAX + 5];
int n, m, dl[8] = {-1, -1, -1, 0, 1, 1, 1, 0}, dc[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
queue< pair<int, int> > q;
bool valid(int i, int j) { return i && j && i <= n && j <= m; }
void read(int l) {
string s;
getline(fin, s);
int c = 1;
for(string :: iterator it = s.begin(); it < s.end(); it++, c++) {
if(*it == 'R')
q.push({l, c}), a[l][c].rj = 'R', a[l][c].t = 1;
if(*it == 'J')
q.push({l, c}), a[l][c].rj = 'J', a[l][c].t = 1;
if(*it == ' ' || *it == 'X')
a[l][c].t = (*it == ' ') ? 0 : 1;
}
while(c <= m) a[l][c].t = 0, c++;
}
int main()
{
fin >> n >> m;
fin.get();
for(int l = 1; l <= n; l++) read(l);
fin.close();
while(!q.empty()) {
for(int i = 0; i < 8; i++) {
int l = q.front().first, c = q.front().second;
int x = l + dl[i], y = c + dc[i];
if(!valid(x, y)) continue;
if(!a[x][y].t) {
q.push({x, y});
a[x][y].rj = a[l][c].rj, a[x][y].t = a[l][c].t + 1;
continue;
}
if(a[l][c].rj == 'R' && a[x][y].rj == 'J') {
fout << a[l][c].t + 1 << " " << x << " " << y;
return 0;
}
if(a[l][c].rj == 'J' && a[x][y].rj == 'R') {
fout << a[l][c].t + 1 << " " << x << " " << y;
return 0;
}
}
q.pop();
}
}