Cod sursa(job #2490223)

Utilizator stefzahZaharia Stefan Tudor stefzah Data 9 noiembrie 2019 22:10:29
Problema Fractal Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <fstream>
#include <iostream>

using namespace std;
int k, x, y;
int P = 1, P1= 1;

int fractal(int xx, int yy) {
    //cout << p << "\n";
    //if (P == 1) return 0;
    P /= 2;
    P1 /= 4;
    if (P == 0) return 0;
    if (xx <= P && yy <= P) {
        return fractal(yy, xx);
    }
    if (xx <= P && yy > P) {
        yy -= P;
        return P1 + fractal(xx, yy);
    }
    if (xx > P && yy > P) {
        xx -= P;
        yy -= P;
        return P1 * 2 + fractal(xx, yy);

    }
    if (xx > P && yy <= P) {
        int aux = xx;
        xx = P - yy + 1;
        yy = 2 * P - aux + 1;
        return P1 * 3 + fractal(xx, yy);
    }

}

int main() {
    ifstream fin("fractal.in");
    ofstream fout("fractal.out");
    fin >> k >> x >> y;
    for (int i = 1; i <= k; i++)
        P *= 2;

    for (int i = 1; i <= k; i++)
        P1 *= 4;

    fout << fractal(x, y);
}