Pagini recente » Cod sursa (job #483168) | Cod sursa (job #2322457) | Cod sursa (job #2111952) | Cod sursa (job #2192847) | Cod sursa (job #2477720)
#include <bits/stdc++.h>
using namespace std;
ifstream ci("rj.in");
ofstream cou("rj.out");
struct coord{
int x,y;
};
int n,m,leej[101][101],leer[101][101],v[101][101];
queue<coord>qr;
queue<coord>qj;
int coordx[5]={-1,0,1,0 };
int coordy[5]={0,1,0,-1 };
void citire(){
coord w;
ci>>n>>m;
string s;
int i,j;
getline(ci,s);
//cout<<s<<endl;
for(i=1;i<=n;i++){
getline(ci,s);
for(j=0;j<=m-1;j++){
if(s[j]=='R' ){v[i][j+1]=1;w.x=i;w.y=j+1;qr.push(w); }
if(s[j]=='J' ){v[i][j+1]=1;w.x=i;w.y=j+1;qj.push(w); }
if(s[j]==' ' ){v[i][j+1]=0; }
if(s[j]=='X' ){v[i][j+1]=2; }
}
}
}
bool Ok(int i,int j){
if(i>=1&&i<=n&&j>=1&&j<=m){
return 1;}
return 0;
}
void Lee(int lee[101][101], queue<coord>q ){
int i,j;
coord w,w1;
while(!(q.empty())){
w=q.front();
q.pop();
for(i=0;i<=3;i++){
w1.x=w.x+coordx[i];
w1.y=w.y+coordy[i];
if(Ok(w1.x,w1.y) ){
if(v[w1.x][w1.y]!=2&&v[w1.x][w1.y]!=1 ){
if(lee[w1.x][w1.y]==0||(lee[w1.x][w1.y]>lee[w.x][w.y]+1 ) ){
lee[w1.x][w1.y]=lee[w.x][w.y]+1;
q.push(w1);
}
}
}
}
}
}
int main()
{
int i,j,mn=200,mni,mnj;
citire();
Lee(leer,qr);
Lee(leej,qj);
/*
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
cout<<leej[i][j]<<" ";
}
cout<<'\n';
}
*/
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
if(leej[i][j]==leer[i][j]&&leej[i][j]&&leer[i][j] ){
if(leej[i][j]<mn ){mn=leej[i][j];mni=i;mnj=j; }
}
}
}
for(j=1;j<=m;j++){
for(i=1;i<=n;i++){
if(leej[i][j]==mn ){mni=i;mnj=j;i=n+1;j=m+1; }
}
}
cou<<mn<<" "<<mni<<" "<<mnj;
}