Cod sursa(job #2490214)

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

using namespace std;
int k, x, y;
int p = 1, p1 = 1;

int fractal(int X, int Y) {
    //cout << p << "\n";
    if (p == 1) return 0;
    p /= 2;
    p1 /= 4;
    //if (p == 0) return 0;
    if (X <= p && Y <= p) {
        return fractal(Y, X);
    }
    if (X <= p && Y > p) {
        Y -= p;
        return p1 + fractal(X, Y);
    }
    if (X > p && Y > p) {
        X -= p;
        Y -= p;
        return p1 * 2 + fractal(X, Y);

    }
    if (X > p && Y <= p) {
        int aux = X;
        X = p - Y + 1;
        Y = 2 * p - aux + 1;
        return p1 * 3 + fractal(X, Y);
    }

}

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);
}