Pagini recente »
Cod sursă (job #293094)
Cod sursă (job
#293094)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("immortal.in");
ofstream fout("immortal.out");
const int NMAX = 25;
struct battle {
int xs, ys, xf, yf;
};
int n, m, k;
bool A[NMAX][NMAX];
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
battle vec[NMAX * NMAX];
void read() {
fin >> n >> m >> k;
for (int i = 0; i < k; ++ i) {
int x, y;
fin >> x >> y;
A[x][y] = true;
}
}
void print() {
for (int i = 0; i < k - 1; ++ i)
fout << vec[i].xs << " " << vec[i].ys << " " << vec[i].xf << " " << vec[i].yf << "\n";
}
void bkt(int key) {
if (key == k - 1) {
print();
exit(EXIT_SUCCESS);
}
else
for (int i = 1; i <= n; ++ i)
for (int j = 1; j <= m; ++ j)
if (A[i][j]) {
// daca am gasit un nemuritor
for (int it = 0; it < 4; ++ it) {
int x = i + dx[it];
int y = j + dy[it];
int l = i + 2 * dx[it];
int c = j + 2 * dy[it];
if (A[x][y] && l > 0 && l <= n && c > 0 && c <= m && !A[l][c]) {
// daca lupta poate avea loc
A[i][j] = false; // nemuritorul atactor isi paraseste pozitia
A[x][y] = false; // nemuritorul pierzator este eliminat
A[l][c] = true; // noua pozitie a nemuritorului atacator
// se memoreaza batalia
vec[key].xs = i;
vec[key].ys = j;
vec[key].xf = l;
vec[key].yf = c;
bkt(key + 1);
A[i][j] = true;
A[x][y] = true;
A[l][c] = false;
}
}
}
}
int main() {
read();
fin.close();
bkt(0);
fout.close();
return 0;
}