Cod sursa(job #2490218)

Utilizator stefzahZaharia Stefan Tudor stefzah Data 9 noiembrie 2019 22:05:55
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);
}