Cod sursa(job #632020)

Utilizator sebii_cSebastian Claici sebii_c Data 10 noiembrie 2011 01:24:31
Problema Fractal Scor 100
Compilator c Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <stdio.h>

int sum;

void solve(int n, int x, int y)
{
    if (n == 0)
	return;
    
    int p = (1<<(n-1));

    if (x <= p && y <= p)
	solve(n-1, y, x);
    else if (x > p && y <= p) {
	sum += p*p;
	solve(n-1, x-p, y);
    }
    else if (x > p && y > p) {
	sum += 2*p*p;
	solve(n-1, x-p, y-p);
    }
    else {
	sum += 3*p*p;
	solve(n-1, 2*p-y+1, p-x+1);
    } 
}

int main()
{
    freopen("fractal.in", "r", stdin);
    freopen("fractal.out", "w", stdout);
 
    int n, x, y;
    scanf("%d %d %d", &n, &x, &y);
    solve(n, y, x);
    printf("%d\n", sum);
    return 0;
}