Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define N 101
- using namespace std;
- ifstream fin("rj.in");
- ofstream fout("rj.out");
- const int di[] = {0 , 0 , -1 , 1};
- const int dj[] = {-1 , 1 , 0 , 0};
- int a[N][N],b[N][N],n,m;
- int li,ci,ls,cs;
- char s[N];
- int dl[]={-1,-1,-1,1,1,1,0,0};
- int dc[]={1,0,-1,1,0,-1,1,-1};
- void Citire()
- {
- fin>>n>>m;fin.get();
- for(int i=1;i<=n;i++)
- {
- fin.getline(s,N);
- for(int j=0;j<m;j++)
- if(s[j]==' ')a[i][j+1]=b[i][j+1]=0;
- else if(s[j]=='X')a[i][j+1]=b[i][j+1]=-1;
- else if(s[j]=='R'){li=i; ci=j+1;}
- else {ls=i; cs=j+1;}
- }
- }
- bool Inside(int i, int j){return 1<=i && i<=n && 1<=j && j<=m;}
- void Lee(int lin, int col, int c[N][N])
- {
- int L[N*N]={0}, C[N*N]={0};
- int pr, ul;
- int v1, v2;
- int lv, cv;
- pr=ul=1;
- L[1]=lin;
- C[1]=col;
- c[lin][col]=1;
- while(pr<=ul)
- { v1=L[pr]; v2=C[pr++];
- for(int i=0;i<8;i++)
- {
- lv=v1+dl[i];
- cv=v2+dc[i] ;
- if(c[lv][cv]==0 && Inside(lv, cv))
- {
- c[lv][cv]=c[v1][v2]+1;
- L[++ul]=lv; C[ul]=cv;
- }
- }
- }
- }
- void Afisare()
- {
- Lee(li,ci,a);
- Lee(ls,cs,b);
- int mini=N*N, lf, cf;
- for(int i=1;i<=n;i++)
- for(int j=1;j<=m;j++)
- if(a[i][j]==b[i][j] && a[i][j]<mini && a[i][j]>0)
- {
- mini=a[i][j];lf=i;cf=j;
- }
- fout<<mini<<" "<<lf<<" "<<cf;
- }
- int main()
- {
- Citire();
- Afisare();
- }
Advertisement
Add Comment
Please, Sign In to add comment