# How to Solve Lee Algorithm in C ++?

I am trying to solve a C ++ problem with Lee's (maze) algorithm. I need to find a place where two people meet at the same time (shortest) knowing that R and J are where they start and X are obstacles. This is what rj.in looks like:

```
5 8
XXR XXX
X X X
J X X X
XX
XXX XXXX
```

And the problem is, when I read it, it always has the same meaning. What am I doing wrong? This is my code and here's where the problem comes in:

```
#include <iostream>
#include <queue>
#include <cstdio>
using namespace std;
#define ex -1
#define red(X) scanf("%d",&X);
const int MAX=150;
int ro [MAX][MAX],ju [MAX][MAX];
inline int inside(int x,int y,int n,int m)
{
return x>=1 and x<=n and y>=1 and y<=m;
}
queue<pair<int,int> > Qr;
queue<pair<int,int> > Qj;
int dx[]={0,0,-1,1};
int dy[]={1,-1,0,0};
int main()
{ freopen("rj.in","r",stdin);
freopen("rj.out","w",stdout);
int rx_n,ry_n,jx_n,jy_n,n,m,i,j,t;
red(n);
red(m);
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
{
red(t);
printf("%d ",t);
if((char)t=='X') {ro[i][j]=-1; ju[i][j]=-1; }
if((char)t=='R') {ro[i][j]=1; Qr.push(make_pair(i,j));}
if((char)t=='J') {ju[i][j]=1; Qj.push(make_pair(i,j));}
}
```

I use C functions because they are faster.

+3

source to share

No one has answered this question yet

Check out similar questions: