Pagini recente » Diferente pentru runda/probleme_oji_clasa_9 intre reviziile 3 si 4 | Diferente pentru home intre reviziile 202 si 201 | Istoria paginii utilizator/dragosmates | Istoria paginii utilizator/stefy0196 | Cod sursa (job #1453669)
#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)
y = (y - 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;
}