Pagini recente » Cod sursa (job #2310871) | Cod sursa (job #1115989) | Cod sursa (job #2098177) | Cod sursa (job #1901256) | Cod sursa (job #1438789)
//0034
#include <cstdio>
int f(int put, int x, int y) {
if (put == 0)
return 0;
bool stanga = (x <= put), jos = (y > put);
int c = 0;
if (stanga && jos)
c = 1;
if (!stanga && jos)
c = 2;
if (!stanga && !jos)
c = 3;
if (c == 0) {
int aux = x;
x = y;
y = aux;
}
if (c == 3) {
x = (x - 1) % put + 1;
int aux = x;
x = put + 1 - y;
y = put +1 - aux;
}
if (c == 1)
x = (x - 1) % put + 1;
if (c == 2) {
x = (x - 1) % put + 1;
y = (y - 1) % put + 1;
}
return c * put * put + f(put / 2, x, y);
}
int main() {
FILE* fi = fopen("fractal.in", "rt");
FILE* fo = fopen("fractal.out", "wt");
int k, x, y;
fscanf(fi, "%d%d%d", &k, &x, &y);
int put = 1;
for (int i = 1; i < k; i++)
put *= 2;
fprintf(fo, "%d", f(put, x, y));
return 0;
}