Pagini recente » Cod sursa (job #2320684) | Cod sursa (job #3152454) | Cod sursa (job #1095472) | Cod sursa (job #2167081) | Cod sursa (job #2490227)
#include <fstream>
#include <iostream>
using namespace std;
int k, x, y;
int P = 1, P1= 1;
int fractal(int xx, int yy) {
//cout << p << "\n";
if (P == 1) return 0;
P /= 2;
P1 /= 4;
//if (P == 0) return 0;
if (xx <= P && yy <= P) {
return fractal(yy, xx);
}
if (xx <= P && yy > P) {
yy -= P;
return P1 + fractal(xx, yy);
}
if (xx > P && yy > P) {
xx -= P;
yy -= P;
return P1 * 2 + fractal(xx, yy);
}
int aux = xx;
xx = P - yy + 1;
yy = 2 * P - aux + 1;
return P1 * 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;
for (int i = 1; i <= k; i++)
P1 *= 4;
fout << fractal(x, y);
}