Pagini recente » Cod sursa (job #1646412) | Cod sursa (job #1042842) | Cod sursa (job #2763968) | Cod sursa (job #194754) | Cod sursa (job #1992010)
#include <fstream>
#include <iostream>
using namespace std;
int fractal(int k, int x, int y) {
int pw = 1 << (k-1);
if(k == 1) {
if(x == 1 && y == 1) {
return 0;
} else if(x == 1 && y == 2) {
return 1;
} else if(x == 2 && y == 2) {
return 2;
} else {
return 3;
}
} else {
if(x > pw && y > pw) {
return 2*pw*pw + fractal(k-1, x - pw, y - pw);
} else if(x > pw && y <= pw) {
return 3*pw*pw + fractal(k-1, pw - y + 1, 2*pw - x + 1);
} else if (x <= pw && y > pw) {
return pw*pw + fractal(k-1, x, y - pw);
} else {
return fractal(k-1, y, x);
}
}
return 6;
}
int main() {
int k, x, y;
ifstream fin("fractal.in");
fin >> k >> x >> y;
ofstream fout("fractal.out");
fout << fractal(k, x, y);
return 0;
}