Pagini recente » Cod sursa (job #3286172) | Cod sursa (job #2254198) | Cod sursa (job #529339) | Cod sursa (job #562008) | Cod sursa (job #2658033)
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
ifstream f ("rj.in");
ofstream g ("rj.out");
int n, m, a[105][105], b[105][105], c[105][105];
priority_queue<tuple<int, int, int>> pq;
int romeo_x, romeo_y, juliet_x, juliet_y;
int dl[]={-1, 0, 1, 0, -1, 1, -1, 1};
int dc[]={0, 1, 0, -1, -1, 1, 1, -1};
bool check(int x, int y)
{
if(x>=1 && y>=1 && x<=n && y<=m && a[x][y]==0)
return 1;
return 0;
}
void lee(int x, int y)
{
for(int i=0; i<8; i++)
{
int next_x=x+dl[i];
int next_y=y+dc[i];
if(check(next_x, next_y) && b[next_x][next_y]==1000)
{
b[next_x][next_y]=1+b[x][y];
lee(next_x, next_y);
}
}
}
void lee2(int x, int y)
{
if(b[x][y]==c[x][y]) pq.push(make_tuple(-b[x][y], -x, -y));
for(int i=0; i<8; i++)
{
int next_x=x+dl[i];
int next_y=y+dc[i];
if(check(next_x, next_y) && c[next_x][next_y]==1000)
{
c[next_x][next_y]=1+c[x][y];
lee2(next_x, next_y);
}
}
}
int main()
{
f>>n>>m;
char x;
f.get(x);
for(int i=1; i<=n; i++)
{
int ok=0;
for(int j=1; j<=m; j++)
{
f.get(x);
b[i][j]=1000;
c[i][j]=1000;
if(x=='X')
{
a[i][j]=-1;
}
else if (x=='R')
{
romeo_x=i;
romeo_y=j;
a[i][j]=0;
b[i][j]=0;
c[i][j]=0;
}
else if (x=='J')
{
juliet_x=i;
juliet_y=j;
a[i][j]=0;
b[i][j]=0;
c[i][j]=0;
}
else if (x==' ')
{
a[i][j]=0;
}
else if (x=='\n')
{
while(j<=m)
{
ok=1;
a[i][j]=0;
j++;
}
}
}
if(ok==0) f.get(x);
}
lee(romeo_x, romeo_y);
lee2(juliet_x, juliet_y);
tuple<int, int, int> res=pq.top();
cout<<-get<0>(res)<<" "<<-get<1>(res)<<" "<<-get<2>(res)<<"\n";
return 0;
}