Pagini recente »
Clasament tema_1_cls7_2018
|
Istoria paginii runda/2024-01-21-clasa-8-tema-14/clasament
|
stefan_eliminare
|
Clasament concurs_cls6_v2
|
Cod sursă (job #309388)
Cod sursă (job
#309388)
#include <bits/stdc++.h>
#define nmax 21
using namespace std;
ifstream fin("immortal.in");
ofstream fout("immortal.out");
bool a[nmax][nmax],sol;
int n,m,nrnemuritori;
struct Patru
{
int xi,yi,xf,yf;
};
Patru st[nmax*nmax];
int top;
void Read()
{
int i,x,y;
fin>>n>>m>>nrnemuritori;
for(i=1;i<=nrnemuritori;i++)
{
fin>>x>>y;
a[x][y]=true;
}
}
inline bool Inauntru(int x,int y)
{
if(1<=x && x<=n && 1<=y && y<=m)
return true;
return false;
}
void Afisare(int top)
{
int i;
for(i=1;i<=top;i++)
fout<<st[i].xi<<" "<<st[i].yi<<" "<<st[i].xf<<" "<<st[i].yf<<"\n";
}
void Back(int top)
{
if(top==nrnemuritori)
{
Afisare(top-1);
sol=true;
}
else
{
for(int i=1;i<=n && !sol;i++)
for(int j=1;j<=m && !sol;j++)
if(a[i][j])/// am gasit un posibil "nemuritor"
{
/// Nord
if(a[i-1][j] && Inauntru(i-2,j) && !a[i-2][j])
{
a[i-2][j]=true;
st[top].xi=i;
st[top].yi=j;
st[top].xf=i-2;
st[top].yf=j;
a[i-1][j]=a[i][j]=false;
Back(top+1);
a[i-2][j]=false;
a[i-1][j]=a[i][j]=true;
}
///Sud
if(a[i+1][j] && Inauntru(i+2,j) && !a[i+2][j])
{
a[i+2][j]=true;
st[top].xi=i;
st[top].yi=j;
st[top].xf=i+2;
st[top].yf=j;
a[i+1][j]=a[i][j]=false;
Back(top+1);
a[i+2][j]=false;
a[i+1][j]=a[i][j]=true;
}
///Est
if(a[i][j+1] && Inauntru(i,j+2) && !a[i][j+2])
{
a[i][j+2]=true;
st[top].xi=i;
st[top].yi=j;
st[top].xf=i;
st[top].yf=j+2;
a[i][j+1]=a[i][j]=false;
Back(top+1);
a[i][j+2]=false;
a[i][j+1]=a[i][j]=true;
}
/// VEST
if(a[i][j-1] && Inauntru(i,j-2) && !a[i][j-2])
{
a[i][j-2]=true;
st[top].xi=i;
st[top].yi=j;
st[top].xf=i;
st[top].yf=j-2;
a[i][j-1]=a[i][j]=false;
Back(top+1);
a[i][j-2]=false;
a[i][j-1]=a[i][j]=true;
}
}
}
}
int main()
{
Read();
Back(1);
fin.close();
fout.close();
return 0;
}