Pagini recente » Cod sursa (job #407674) | Cod sursa (job #2748902) | Cod sursa (job #494786) | Cod sursa (job #2543301) | Cod sursa (job #2819167)
#include <iostream>
using namespace std;
pair <int,int> poz[15];
int mat[25][25];/// =index nemuritori de la fiecare poz
int mort[15];
pair < pair <int,int> , pair <int,int> > mutari[14];
int dx[] = { -1, 1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };
int nri; ///=nr de immortali
int n, m;
bool inb(int a, int b)
{
return 0 <= a && a < n && 0 <= b && b < m;
}
bool canland(int a, int b, int k)
{
return mat[a][b] != 0 && inb(a + dx[k], b + dy[k]);
}
void bk(int alive)
{
if (alive == 1)
{
///afiseaza();
cout << ":)";
return;
}
for (int i = 0; i < nri; i++)
{
if (!mort[i])
{
int x = poz[i].first;
int y = poz[i].second;
for (int k = 0; k < 4; ++k)
{
int xx = x + dx[k];
int yy = y + dy[k];
if (inb(xx, yy) && canland(xx, yy, k))
{
mutari[nri - alive] = {{x, y}, {xx + dx[k], yy + dy[k]}};
int inamic = mat[xx][yy];
mort[inamic] = 1;
mat[xx][yy] = 0;
///poz[i] += {xx + dx[k], yy + dy[k]};///d * 2;
poz[i].first += xx + dx[k];
poz[i].second += yy + dy[k];
bk(alive - 1);
mort[inamic] = 0;
mat[xx][yy] = inamic;
///poz[i] -= {xx + dx[k], yy + dy[k]};///d * 2;
poz[i].first -= xx + dx[k];
poz[i].second -= yy + dy[k];
}
}
}
}
}
int main()
{
int x, y;
cin >> n >> m >> nri;
for (int i = 0; i < nri; ++i)
{
cin >> x >> y;
poz[i] = {x, y};
mat[x][y] = i;
}
bk(nri);
return 0;
}