Pagini recente » Cod sursa (job #2316636) | Cod sursa (job #1279763) | Cod sursa (job #1732980) | Cod sursa (job #168444) | Cod sursa (job #882391)
Cod sursa(job #882391)
#include <fstream>
//http://www.youtube.com/watch?v=5W_wd9Qf0IE !!!!!
using namespace std;
const int dy[]={0,1,0,-1};
const int dx[]={-1,0,1,0};
int k;//http://www.youtube.com/watch?v=iat1VmplWOM
int xR,yR,xJ,yJ;
int turbofin=7991;
int i,j,l;
int mata[102][102];// Pai cred ca e oarecum okay, adica, ma asteptam la asta, dar in acelasi timp opinia mea e ca nu ar trebui sa renunti la un prieten asa de usor, mai ales ca eu inca incerc sa ramanem prietnei, tu l-ai evacuat nu el pe tine si acum e oarecum okay ca ii ceri parerea dar nu stie ce sa creada.
int cazuri[99*99][2],IGLOBAL=0;
//limerenceee: http://www.youtube.com/watch?v=6eBBniJy0tg
void LeestenToMeRomeo(int ii,int jj,int c)
{
int kp,a,b;
for(kp=0;kp<4;kp++)
{
a=ii+dx[kp];
b=jj+dy[kp];
{
if((a==xJ)&&(b==yJ)&&c/2+1<turbofin)
{
turbofin=c/2+1;
}
else if(((mata[a][b]==0)||(mata[a][b]>c+1))&&mata[a][b]!=-1)
{
mata[a][b]=c+1;
LeestenToMeRomeo(a,b,c+1);
}
}
}
}
int JulietJustCheckAround(int ii,int jj,int bh)
{
int kp,a,cs=0,b;
for(kp=0;kp<4;kp++)
{
a=ii+dx[kp];
b=jj+dy[kp];
//http://www.youtube.com/watch?v=27Bh1D18lto
if(mata[a][b]==bh)
{
cs++;
}
}
if(cs==2)
return 1;
return 0;
}
//http://www.youtube.com/watch?v=y7sZHfrLdI8
void LadyJulietDoTheTwist(int ii,int jj,int cac)
{
int kp,a,b;
if(cac<turbofin)
{
//http://www.youtube.com/watch?v=LMi9iYkmmpw
for(kp=0;kp<4;kp++)
{
a=ii+dx[kp];
b=jj+dy[kp];
//http://www.youtube.com/watch?v=CUCye-RjG8g
if(((mata[a][b]==0)||(mata[a][b]>cac+1))&&mata[a][b]!=-1)
{
mata[a][b]=cac+1;
LadyJulietDoTheTwist(a,b,cac+1);
}
}
}
}
int main()
{
ifstream g("rj.in");
int kk=0;
char v[101];
g>>k>>l;
for(i=0;i<=k;i++)
{
g.getline(v,l+1);
for(j=1;j<=l;j++)
{
if(kk!=2)
{
if(v[j-1]=='X')mata[i][j]=-1;
else if(v[j-1]==' ')mata[i][j]=0;
else if(v[j-1]=='R')
{
xR=i;
yR=j;
kk++;
}
else if(v[j-1]=='J')
{
xJ=i;
yJ=j;
kk++;
}
}
else
{
if(v[j-1]=='X')mata[i][j]=-1;
else if(v[j-1]==' ')mata[i][j]=0;
}
}
}
//bordizification
for(i=0;i<=(l<k?k:l);i++)
{
mata[i][0]=-1;
mata[i][k+1]=-1;
mata[0][i]=-1;
mata[l+1][i]=-1;
}
LeestenToMeRomeo(xR,yR,0);
LadyJulietDoTheTwist(xJ,yJ,0);
for(i=1;i<=k;i++)
for(j=1;j<=l;j++)
if(mata[i][j]==turbofin)
if(JulietJustCheckAround(i,j,turbofin-1)==1)
{
cazuri[IGLOBAL][0]=i;
cazuri[IGLOBAL][1]=j;
IGLOBAL++;
}
//In cazul existentei mai multor solutii se va afisa solutia in care linia punctului de intalnire este minima.
//Daca si asa exista mai multe solutii, se va afisa cea in care coloana punctului de intalnire este minima.
if(IGLOBAL>1)
{
mata[0][0]=26267;
mata[0][1]=0;
for(i=0;i<IGLOBAL;i++)
{
if(cazuri[i][0]<mata[0][0])
{
mata[0][0]=cazuri[i][0];
mata[0][1]++;
mata[1][0]=cazuri[i][0];
mata[1][1]=cazuri[i][1];
}
}
if(mata[0][1]>1)
{
mata[0][2]=26267;
for(i=0;i<IGLOBAL;i++)
if(cazuri[i][0]==mata[0][0])
{
if(cazuri[i][1]<mata[0][2])
{
mata[0][2]=cazuri[i][1];
mata[1][0]=cazuri[i][0];
mata[1][1]=cazuri[i][1];
}
}
}
cazuri[0][0]=mata[1][0];
cazuri[0][1]=mata[1][1];
}
ofstream o("rj.out");
o<<turbofin<<" "<<cazuri[0][0]<<" "<<cazuri[0][1];
return 0;
}