Cod sursa(job #1470330)

Utilizator StarGold2Emanuel Nrx StarGold2 Data 10 august 2015 20:58:47
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <cstdio>
using namespace std;

int K, X, Y;

int Count(int K, int X, int Y){

    if(K == 0) return 0;

    int MID = (1 << (K - 1));

    if(X <= MID && Y <= MID)
        return MID * MID * 0 + Count(K - 1,        Y       ,      X     );

    if(X <= MID && Y  > MID)
        return MID * MID * 3 + Count(K - 1, 2 * MID - Y + 1, MID - X + 1);

    if(X  > MID && Y <= MID)
        return MID * MID * 1 + Count(K - 1,     X - MID    ,      Y     );

    if(X  > MID && Y  > MID)
        return MID * MID * 2 + Count(K - 1,     X - MID    ,   Y - MID  );

    return 0;
}

int main(){

    freopen("fractal.in" ,"r", stdin );
    freopen("fractal.out","w", stdout);

    scanf("%d %d %d", &K, &X, &Y);

    printf("%d\n",Count(K, Y, X));

    fclose(stdin );
    fclose(stdout);

    return 0;
}