Pagini recente » Cod sursa (job #2426263) | Cod sursa (job #569841) | Cod sursa (job #3250060) | Cod sursa (job #2567239) | Cod sursa (job #2490218)
#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);
}
if (xx > p && yy <= p) {
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);
}