Cod sursa(job #2232243)

Utilizator DandeacDan Deac Dandeac Data 18 august 2018 01:57:49
Problema Rj Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.6 kb
#include <iostream>
#include <fstream>
#include <queue>
#define MAX_MAT 110
using namespace std;
ifstream f ("rj.in");
ofstream g ("rj.out");

int rj[MAX_MAT][MAX_MAT], N, M, x1, y1, x2, y2;
int x,y,CX,CY;
queue <int> qx,qy;
const int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};
bool le2 = false;
void lee(){

    qx.push(x1);
    qy.push(y1);

    while(!qx.empty())
    {
        x=qx.front();
        y=qy.front();

        qx.pop();
        qy.pop();

        for(int i=0;i<4;i++)
        {
            CX = x + dx[i];
            CY = y + dy[i];

            if(CX>0 && CY>0 && CX<=N && CY<=N && (rj[CX][CY] == 0 || rj[CX][CY]>=rj[x][y] + 1))
            {
                qx.push(CX);
                qy.push(CY);
                rj[CX][CY] = rj[x][y] + 1;
            }
        }
    }

    if(le2) g<<rj[x][y] - 1<<' '<<x<<' '<<y;

}
char punct;

int main()
{

 f>>N>>M;
    f.get(punct);
    for(int i=1;i<=N;i++)
    {
         for(int j=1;j<=M;j++)
        {
            f.get(punct);
            if(punct == 'X')
                rj[i][j] = -1;
            else if(punct == 'R')
            {
                 rj[i][j] = 1;
                 x1=i;y1=j;

            }else if(punct == 'J')
            {
                rj[i][j] = 1;
                x2=i;y2=j;
            }
            else  rj[i][j] = 0;

        }if(punct == 'R' || punct == 'J' || punct == 'X')
        f.get(punct);
    }
    lee();

    int aux1,aux2;
    aux1 = x1;
    x1=x2;
    x2=aux1;

    aux2=y1;
    y1=y2;
    y2=aux2;

    le2 = true;
    lee();

    return 0;
}