Pagini recente » Cod sursa (job #199422) | Cod sursa (job #3030275) | Cod sursa (job #2827196) | Cod sursa (job #1419488) | Cod sursa (job #472668)
Cod sursa(job #472668)
#include <stdio.h>
int rec(int k, int x, int y) {
printf("%d %d %d\n", k, x, y);
if (!k) return 0;
int new_k = k - 1;
int s = 1 << new_k;
bool up = y <= s;
bool left = x <= s;
if (!up) y -= s;
if (!left) x -= s;
if (up & left) return rec(new_k, y, x);
else if (!up & left) return s * s + rec(new_k, x, y);
else if (!up) return 2 * s * s + rec(new_k, x, y);
else return 3 * s * s + rec(new_k, s + 1 - y, s + 1 - x);
}
int main() {
int k, x, y;
fscanf(fopen("fractal.in", "rt"), "%d %d %d", &k, &x, &y);
fprintf(fopen("fractal.out", "wt"), "%d\n", rec(k, x, y));
return 0;
}