Pagini recente » Cod sursa (job #2618248) | Cod sursa (job #1143073) | Cod sursa (job #2402127) | Cod sursa (job #2296482) | Cod sursa (job #2490237)
#include <fstream>
#include <iostream>
#define Q P*P
using namespace std;
int k, X, Y;
int P = 1;
int Fractal(int xx, int yy) {
P /= 2;
int x=0;
if (P == 0) return 0;
if (xx <= P && yy <= P) {
return Fractal(yy, xx);
}
if (xx <= P && yy > P) {
yy -= P;
return Q + Fractal(xx, yy);
}
if (xx > P && yy > P) {
xx -= P;
yy -= P;
return Q * 2 + Fractal(xx, yy);
}
if (xx > P && yy <= P) {
int aux = xx;
xx = P - yy + 1;
yy = 2 * P - aux + 1;
return Q * 3 + Fractal(xx, yy);
}
}
int main() {
ifstream fin("fractal.in");
ofstream fout("fractal.out");
fin >> k >> X >> Y;
for (int i = 1; i <= k; i++)
P *= 2;
fout << Fractal(X, Y);
}
/*
8 2 3
4 3 2
2 1 2
1 1 1
*/