Cod sursa(job #980489)

Utilizator Mihai22eMihai Ionut Enache Mihai22e Data 4 august 2013 19:42:19
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <fstream>
using namespace std;

int N, x, y;

inline int compute(int N, int x, int y) {
    if(N == 0)
        return 0;
    int m = (1 << (N-1));
    if(x <= m && y <= m)
        return compute(N-1, y, x);
    else if(x <= m && y > m)
        return m*m*3 + compute(N-1, 2*m-y+1, m-x+1);
    else if(x > m && y <= m)
        return m*m + compute(N-1, x-m, y);
    else return m*m*2 + compute(N-1, x-m, y-m);
}

int main() {
    ifstream f("fractal.in");
    ofstream g("fractal.out");

    f >> N >> y >> x;
    g << compute(N, x, y) << "\n";

    f.close();
    g.close();

    return 0;
}