Cod sursa(job #2696634)

Utilizator Gicu12345Puradelul Albastru Gicu12345 Data 16 ianuarie 2021 11:18:16
Problema Rj Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.99 kb
#include <fstream>
#include <queue>
using namespace std;
int tl[] = {-1, 0, 1, 0, 1, 1, -1, -1};
int tc[] = {0, 1, 0, -1, 1, -1, -1, 1};
int n, m, vj[105][105], vr[105][105], stxr, styr, stxj, styj;
int minx=100005, miny=100005, mint=100005;
queue<int>x, y;
string s;
int lee(int stx, int sty, int v[105][105])
{
    int xx, yy, curx, cury;
    curx=stx;
    cury=sty;
    x.push(stx);
    y.push(sty);
    v[stx][sty]=1;
    while(!x.empty())
    {
        curx=x.front();
        cury=y.front();
        for(int i=0;i<8;i++)
        {
            xx=curx+tl[i];
            yy=cury+tc[i];
            if(xx<=n&&yy<=m&&xx>=0&&yy>=0&&v[xx][yy]==0)
            {
                v[xx][yy]=v[curx][cury]+1;
                x.push(xx);
                y.push(yy);
            }
        }
        x.pop();
        y.pop();
    }
}
ifstream cin ("rj.in");
ofstream cout("rj.out");
int main()
{
    cin>>n>>m;
    cin.ignore();
    for(int i=0;i<n;i++)
    {
        getline(cin, s);
        for(int j=0;j<m;j++)
        {
            if(s[j]=='X')
            {
                vr[i][j]=-1;
                vj[i][j]=-1;
            }
            else if(s[j]==' ')
            {
                vr[i][j]=0;
                vj[i][j]=0;
            }
            else if(s[j]=='R')
            {
                stxr=i;
                styr=j;
                vj[i][j]=-1;
            }
            else
            {
                stxj=i;
                styj=j;
                vr[i][j]=-1;
            }
        }
    }
    lee(stxr, styr, vr);
    lee(stxj, styj, vj);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(vj[i][j]==vr[i][j]&&vj[i][j]>=1)
            {
                if(vj[i][j]<mint)
                {
                    minx=i;
                    miny=j;
                    mint=vj[i][j];
                }
            }
        }
    }
    cout<<mint<<" "<<minx+1<<" "<<miny+1;
    return 0;
}