Cod sursa(job #1016296)

Utilizator nicuvladNicu Vlad nicuvlad Data 26 octombrie 2013 00:13:52
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <stdio.h>
#define pw (1 << K)

int solve(int K, int x, int y) {
    if (K == 0)
        return 0;
    --K;
    if (x <= pw && y <= pw)
        return solve(K, y, x);
    if (x > pw && y <= pw)
        return pw * pw + solve(K, x - pw, y);
    if (x > pw && y > pw)
        return 2 * pw * pw + solve(K, x - pw, y - pw);
    return 3 * pw * pw + solve(K, 2 * pw - y + 1, pw - x + 1);
}

int main()
{
    freopen("fractal.in", "r", stdin);
    freopen("fractal.out", "w", stdout);
    int K, x, y;
    scanf("%d%d%d", &K, &y, &x);
    printf("%d", solve(K, x, y));

}