Cod sursa(job #1003039)

Utilizator rebound212Mihnea Savu rebound212 Data 29 septembrie 2013 17:42:55
Problema Rj Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.48 kb
#include <cstdio>

using namespace std;
const int dx[4]= {-1,1,0,0};
const int dy[4]= {0,0,-1,1};

int u,a[101][101],x,y,j,i,p,xx,yy,n,m,xi,yi,xf,yf,lol;
char c;
bool ok;
struct punct
{
    int c;
    int l;
    int lg;
};
punct Q[10005];
punct nod;
void lee()
{
    Q[1].lg=0;
    Q[1].l=xi;
    Q[1].c=yi;
    p=1;
    u=1;
    ok=false;
    while(!ok)
    {

        nod=Q[p];
        x=nod.l;
        y=nod.c;
        for(i=0; i<=3; i++)
        {
            xx=x+dx[i];

            yy=y+dy[i];
            if( a[xx][yy]==0){

            a[xx][yy]=nod.lg+1;
            u++;
            Q[u].l=xx;
            Q[u].c=yy;
            Q[u].lg=nod.lg+1;
        }}
        if(a[xf][yf]!=0) { printf("%d ",(a[xf][yf]+1)/2); lol=(a[xf][yf]+1)/2; ok=true;}
        p++;
    }

}

int main()
{
    freopen("rj.in","r",stdin);
    freopen("rj.out","w",stdout);
    scanf("%d %d\n",&n,&m);
for(i=0; i<=n+1; i++)
    {
        for(j=0; j<=n+1; j++)
            a[i][j]=-1;
    }
    for(i=1;i<=n;++i)
    {
        for(j=1;j<=m;++j)
        {
            scanf("%c",&c);
            if(c=='R') {xi=i; yi=j; a[i][j]=0;}
            if(c=='J') {xf=i; yf=j; a[i][j]=0;}
            if(c=='X') a[i][j]==-1;
            if(c==' ') a[i][j]=0;
        }
        scanf("%c",&c);


    }
    lee();
    ok=true;
   while(ok)
   {
 if(Q[u].lg!=lol)
   {u--;}
if(Q[u].lg==lol)
{printf("%d %d",Q[u].l,Q[u].c);
   ok=false;}
   }

    return 0;
}