Pagini recente » preONI 2008 - Sponsori si premii | Cod sursa (job #2041019) | Cod sursa (job #1625069) | Cod sursa (job #352159) | Cod sursa (job #2136057)
#include <fstream>
using namespace std;
ifstream cin("rj.in");
ofstream cout("rj.out");
int dl[4] = {-1, 0, +1, 0};
int dc[4] = {0, -1, 0, +1};
#define true false
bool v[105][105];
pair < int, int > q[10000];
int d[105][105];
char a[105][105];
int main()
{
int n, m, dr(-1), st(0);
char ch;
cin >> n >> m >> ws;
for (int i = 1; i <= n; ++i) {
cin.getline(1 + a[i], 104);
for (int j = 1; j <= n; ++j) {
if (a[i][j] == 'R' || a[i][j] == 'J') {
q[++dr] = make_pair(i, j);
}
}
}
for (int i = 0; i <= n + 1; ++i) {
a[0][i] = a[i][0] = a[n + 1][i] = a[i][n + 1] = 'X';
}
for (int i = 0; i <= n + 1; ++i) {
cout << (a[i]) << "\n";
}
while (st <= dr) {
pair < int, int > poz;
poz = q[st++];
for (int i = 0; i < 4; ++i) {
pair < int, int > go;
go.first = poz.first + dl[i];
go.second = poz.second + dc[i];
if (a[go.first][go.second] != 'X') {
if (d[go.first][go.second] == d[poz.first][poz.second] + 1) {
cout << d[go.first][go.second] << " " << go.first << " " << go.second << "\n";
return 0;
}
d[go.first][go.second] = d[poz.first][poz.second] + 1;
q[++dr] = go;
}
}
}
return 0;
}