Cod sursa(job #2490237)

Utilizator stefzahZaharia Stefan Tudor stefzah Data 9 noiembrie 2019 22:28:42
Problema Fractal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <fstream>
#include <iostream>
#define Q P*P
using namespace std;
int k, X, Y;
int P = 1;
int Fractal(int xx, int yy) {
    P /= 2;
    int x=0;
    if (P == 0) return 0;
    if (xx <= P && yy <= P) {
        return Fractal(yy, xx);
    }
    if (xx <= P && yy > P) {
        yy -= P;
        return Q + Fractal(xx, yy);
    }
    if (xx > P && yy > P) {
        xx -= P;
        yy -= P;
        return Q * 2 + Fractal(xx, yy);

    }
    if (xx > P && yy <= P) {
        int aux = xx;
        xx = P - yy + 1;
        yy = 2 * P - aux + 1;
        return Q * 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;

    fout << Fractal(X, Y);
}
/*
8 2 3
4 3 2
2 1 2
1 1 1
 */