Pagini recente » Cod sursa (job #1211975) | Cod sursa (job #566038) | Cod sursa (job #2258499) | Cod sursa (job #648585) | Cod sursa (job #1847791)
#include <iostream>
#define in "fractal.in"
#define out "fractal.out"
using namespace std;
int fractal(int k, int x, int y) {
int p = 1 << (k-1);
if (k == 0) {
return 0;
} else if(x <= p && y <=p) {
return fractal(k-1, y, x);
} else if(x<=p && y>p) {
return p*p + fractal(k-1, x, y-p);
} else if(x>p && y > p) {
return 2 * p * p + fractal(k-1, x-p, y-p);
} else {
return 3 * p * p + fractal(k-1, p-y+1, 2*p-x+1);
}
}
int main() {
int k,x,y;
freopen(in, "r", stdin);
freopen(out, "w", stdout);
cin>>k>>x>>y;
cout<<fractal(k,x,y);
return 0;
}