Cod sursa(job #1847791)

Utilizator dan89Stan Alexandru dan89 Data 15 ianuarie 2017 01:03:09
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <iostream>
#define in "fractal.in"
#define out "fractal.out"
using namespace std;

int fractal(int k, int x, int y) {
    int p = 1 << (k-1);

    if (k == 0) {
        return 0;
    } else if(x <= p && y <=p) {
        return fractal(k-1, y, x);
    } else if(x<=p && y>p) {
        return p*p + fractal(k-1, x, y-p);
    } else if(x>p && y > p) {
        return 2 * p * p + fractal(k-1, x-p, y-p);
    } else {
        return 3 * p * p + fractal(k-1, p-y+1, 2*p-x+1);
    }
}


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

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

    cin>>k>>x>>y;

    cout<<fractal(k,x,y);
    return 0;
}