Pagini recente »
Cod sursă (job #495220)
|
concursul_campionilor_1
|
Monitorul de evaluare
|
Monitorul de evaluare
|
Cod sursă (job #295616)
Cod sursă (job
#295616)
#include <bits/stdc++.h>
using namespace std;
ifstream f("immortal.in");
ofstream g("immortal.out");
const int nMax = 25;
struct Pct{
int xs, ys, xf, yf;
};
Pct sol[nMax];
pair <int, int > a[nMax];
int dx[] = {-1,0,1,0};
int dy[] = {0,1,0,-1};
int dx2[] = {-2,0,2,0};
int dy2[] = {0,2,0,-2};
int n ,m;
bool there[nMax][nMax], done;
inline bool Ok(int x, int y) {
if(x > n || x < 1 || y < 1 || y > m) {
return 0;
}
return 1;
}
inline void Back(int top, int nemuritori) {
if(top == nemuritori) {
done = 1;
for(int i = 1; i < top; i++) {
g<< sol[i].xs << " " << sol[i].ys << " " << sol[i].xf << " " << sol[i].yf << "\n";
}
}
for(int i = 1; i <= nemuritori; i++) {
if(done) {
return;
}
int x = a[i].first;
int y = a[i].second;
if(there[x][y]) {
for(int k = 0; k < 4; k++) {
int nx = x + dx[k];
int ny = y + dy[k];
int nxvec = x + dx2[k];
int nyvec = y + dy2[k];
if(Ok(nxvec,nyvec) && there[nx][ny] && !there[nxvec][nyvec]){
there[x][y] = 0;
there[nx][ny] = 0;
there[nxvec][nyvec] = 1;
a[i].first = nxvec;
a[i].second = nyvec;
sol[top].xs = x;
sol[top].ys = y;
sol[top].xf = nxvec;
sol[top].yf = nyvec;
Back(top + 1, nemuritori);
a[i].first = x;
a[i].second = y;
there[x][y] = 1;
there[nx][ny] = 1;
there[nxvec][nyvec] = 0;
}
}
}
}
return;
}
int main()
{
int k;
f >> n >> m >> k;
for(int i = 1; i <= k; i++) {
f>> a[i].first >> a[i].second;
there[a[i].first][a[i].second] = 1;
}
Back(1,k);
return 0;
}