Pagini recente » Cod sursa (job #3269628) | Cod sursa (job #29155) | Cod sursa (job #3213502) | Cod sursa (job #3138093) | Cod sursa (job #130485)
Cod sursa(job #130485)
#include <cstdio>
using namespace std;
static int numar(int k, int x, int y) {
if(1==k) {
int a[2][2] = {{0,3}, {1, 2}};
return a[-1+y][-1+x];
} else {
-- k;
const int c2k = 1<<k;
const int c4k = c2k * c2k;
if(c2k>=x) {
if(c2k>=y) {
return numar(k, y, x);
} else {
return 1 * c4k + numar(k, x, y-c2k);
}
} else {
if(c2k>=y) {
return 3 * c4k + numar(k, c2k + 1 - y, 2 * c2k + 1 - x);
} else {
return 2 * c4k + numar(k, x - c2k, y - c2k);
}
}
}
}
int main () {
int k, x, y;
FILE * io;
io=fopen("fractal.in", "r");
fscanf(io, "%d %d %d", &k, &x, &y);
fclose(io);
io=fopen("fractal.out", "w");
fprintf(io, "%d\n", numar(k, x, y));
fclose(io);
}