Cod sursa(job #2136418)

Utilizator serban_ioan97Ciofu Serban serban_ioan97 Data 19 februarie 2018 21:52:43
Problema Fractal Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <cstdio>

using namespace std;

int dist[2][2] = {0, 3, 1, 2};
int x, y, k;

int divide(int k, int x, int y) {
    if(k == 1) {
        return dist[x - 1][y - 1];
    } else {
        if (y <= 1 << (k - 1)) {
            if (x <= 1 << (k - 1)) {
                return divide(k - 1, y, x);
            } else {
                return divide(k - 1, x - (1 << (k - 1)), y) + (1 << 2*(k - 1));
            }
        } else {
            if (x > 1 << (k - 1)) {
                return divide(k - 1, x - (1 << (k - 1)), y - (1 << (k - 1))) + 2 * (1 << 2*(k - 1));
            } else {
                return (k - 1, (1 << k) - y + 1, (1 << (k - 1)) - x + 1) + 3 * (1 << 2*(k - 1));
            }
        }
    }
}

int main()
{
    freopen("fractal.in", "rt", stdin);
    freopen("fractal.out", "wt", stdout);

    scanf("%d%d%d", &k, &y, &x);

    printf("%d\n", divide(k, x, y));

    return 0;
}