Cod sursa(job #282490)

Utilizator silvia_the_bestSilvia Pripoae silvia_the_best Data 17 martie 2009 18:46:56
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.91 kb
#include <cstdio>
#define FIN "fractal.in"
#define FOUT "fractal.out"

int solve(int k, int x, int y)
{
    int c, cx, cy;
    if (k == 0)
        return 0;
    if (x <= (1 << (k - 1)) && y <= (1 << (k - 1)))
        c = 0;
    else if (x <= (1 << (k - 1)))
        c = 1;
    if (x > (1 << (k - 1)) && y <= (1 << (k - 1)))
        c = 3;
    else if ( x > (1 << (k - 1)))
        c = 2;
    if (c == 1 || c == 2)
    {
        cx = x - (1 << (k - 1)) * (c - 1);
        cy = y - (1 << (k - 1));
    }
    if (c == 0)
    {
        cx = y;
        cy = x;
    }
    if (c == 3)
    {
        cx = (1 << (k - 1)) - y + 1;
        cy = (1 << k) - x + 1;
    }
    return (1 << (2 * k - 2)) * c + solve(k - 1, cx, cy);
}

int main()
{
    int k,x,y;

    freopen(FIN, "r", stdin);
    freopen(FOUT, "w", stdout);

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

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

}